spritely/hoot
15
108
Fork
You've already forked hoot
18

feat: improve diagnostics for duplicate definitions and import collisions #883

Merged
flockofbirbs merged 1 commit from jinser/hoot:issue-877 into main 2026年04月16日 16:59:31 +02:00
Contributor
Copy link

fix: #877

compile

(use-modules)
(define (foo)
 (pk 'do-things))
(define (foo)
 (pk 'do-other-things))

now got

Backtrace:
In ice-9/boot-9.scm:
 1784:12 14 (with-exception-handler _ _ #:unwind? _ # _)
In unknown file:
 13 (apply-smob/0 #<thunk 7f6df6910340>)
In ice-9/boot-9.scm:
 733:2 12 (call-with-prompt _ _ #<procedure default-prompt-handle...>)
In ice-9/eval.scm:
 619:8 11 (_ #(#(#<directory (guile-user) 7f6df6913c80>)))
In /nix/store/dhdkzdm8z10bkbvwngjsh2dw36yihac7-devshell-dir/bin/guild:
 72:17 10 (main _)
In hoot/frontend-cli.scm:
 451:22 9 (dispatch-compile _)
In ice-9/ports.scm:
 439:17 8 (call-with-input-file _ _ #:binary _ #:encoding _ # _)
In hoot/compile.scm:
 601:18 7 (_ _)
 482:4 6 (compile _ #:imports _ #:import-abi? _ #:export-abi? _ # ...)
In hoot/library-group.scm:
 908:9 5 (expand-library-group #<<library-group> src: #("hoot/c...> ...)
In srfi/srfi-1.scm:
 576:18 4 (fold #<procedure program->reversed-bindings (program ...> ...)
In hoot/library-group.scm:
 830:15 3 (program->reversed-bindings _ (#<<definition> name: ...> ...))
 653:4 2 (module->reversed-bindings _ (library-group-program1469) ...)
 603:17 1 (foldts #<tree-il (seq (define foo (lambda ((name . foo...>)
 656:27 0 (_ _)
hoot/library-group.scm:656:27: duplicate top-level definition #("x.scm" 5 0) foo

While Guile (and Hoot before this PR) allows redefinitions from import (treating them as shadowing), this PR enforces strict single-definition semantics, i.e. raise errors on this situation.

(use-modules (hoot apply))
(define apply 1)

got

......
hoot/library-group.scm:656:27: duplicate top-level definition #("x.scm" 1 0) apply

I have a vague feeling this isn't the right approach, but I'm not sure what to do. I really need a reviewer's comment.

fix: #877 compile ```scheme (use-modules) (define (foo) (pk 'do-things)) (define (foo) (pk 'do-other-things)) ``` now got ``` Backtrace: In ice-9/boot-9.scm: 1784:12 14 (with-exception-handler _ _ #:unwind? _ # _) In unknown file: 13 (apply-smob/0 #<thunk 7f6df6910340>) In ice-9/boot-9.scm: 733:2 12 (call-with-prompt _ _ #<procedure default-prompt-handle...>) In ice-9/eval.scm: 619:8 11 (_ #(#(#<directory (guile-user) 7f6df6913c80>))) In /nix/store/dhdkzdm8z10bkbvwngjsh2dw36yihac7-devshell-dir/bin/guild: 72:17 10 (main _) In hoot/frontend-cli.scm: 451:22 9 (dispatch-compile _) In ice-9/ports.scm: 439:17 8 (call-with-input-file _ _ #:binary _ #:encoding _ # _) In hoot/compile.scm: 601:18 7 (_ _) 482:4 6 (compile _ #:imports _ #:import-abi? _ #:export-abi? _ # ...) In hoot/library-group.scm: 908:9 5 (expand-library-group #<<library-group> src: #("hoot/c...> ...) In srfi/srfi-1.scm: 576:18 4 (fold #<procedure program->reversed-bindings (program ...> ...) In hoot/library-group.scm: 830:15 3 (program->reversed-bindings _ (#<<definition> name: ...> ...)) 653:4 2 (module->reversed-bindings _ (library-group-program1469) ...) 603:17 1 (foldts #<tree-il (seq (define foo (lambda ((name . foo...>) 656:27 0 (_ _) hoot/library-group.scm:656:27: duplicate top-level definition #("x.scm" 5 0) foo ``` While Guile (and Hoot before this PR) allows redefinitions from import (treating them as shadowing), this PR enforces strict single-definition semantics, i.e. raise errors on this situation. ```scheme (use-modules (hoot apply)) (define apply 1) ``` got ``` ...... hoot/library-group.scm:656:27: duplicate top-level definition #("x.scm" 1 0) apply ``` I have a vague feeling this isn't the right approach, but I'm not sure what to do. I really need a reviewer's comment.
flockofbirbs left a comment
Copy link

Thanks for the patch! I think throwing an error is the right thing. Just a couple of small comments.

Thanks for the patch! I think throwing an error is the right thing. Just a couple of small comments.
@ -658,0 +656,4 @@
(error "duplicate definition" src name)
(begin (add-definition! defs defs name #f duplicate-handler
(make-lexical (gensym "top")))
(values))))

Use cond instead of an if with a begin. Change error message to say "duplicate top-level definition".

Use `cond` instead of an `if` with a `begin`. Change error message to say "duplicate top-level definition".
Author
Contributor
Copy link

done; squashed into one

done; squashed into one
@ -0,0 +21,4 @@
'no-exception-thrown)
#:unwind? #t)))
(test-begin "test-duplicate-definitions")

I don't think a test case is necessary for this. This file can be removed.

I don't think a test case is necessary for this. This file can be removed.
jinser force-pushed issue-877 from f1efeef5df to 05804424b1
All checks were successful
/ distcheck (push) Successful in 44m39s
2026年04月16日 16:51:28 +02:00
Compare

Looks good! Thank you!

Looks good! Thank you!
jinser deleted branch issue-877 2026年04月16日 17:00:13 +02:00
Sign in to join this conversation.
No reviewers
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
spritely/hoot!883
Reference in a new issue
spritely/hoot
No description provided.
Delete branch "jinser/hoot:issue-877"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?