Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Identifier incorrectly allowed to be "both defined and imported" #8

Open
LiberalArtist opened this issue May 21, 2022 · 2 comments
Open

Comments

@LiberalArtist
Copy link
Contributor

R6RS §7.1 says:

An identifier can be imported with the same local name from two or more libraries or for two levels from the same library only if the binding exported by each library is the same (i.e., the binding is defined in one library, and it arrives through the imports only by exporting and re-exporting). Otherwise, no identifier can be imported multiple times, defined multiple times, or both defined and imported.

Racket's R6RS language currently fails to enforce this requirement.

Consider the following library, saved in a file bug.sls:

#!r6rs
(library (bug)
  (export)
  (import (rnrs base))
  (define + 'plus))

Racket allows this library, but it is rejected (at least) by Chez Scheme (both upstream and Racket's variant):

philip@bastet:~/code/tmp$ racket bug.sls 
philip@bastet:~/code/tmp$ scheme bug.sls 
Chez Scheme Version 9.5.8
Copyright 1984-2022 Cisco Systems, Inc.

Exception: multiple definitions for + in body (library (bug) (export) (import (rnrs base)) (define + (quote plus))) at line 2, char 1 of bug.sls
philip@bastet:~/code/tmp$ guix shell --pure --container chez-scheme-for-racket -- scheme bug.sls
Chez Scheme Version 9.5.7.6
Copyright 1984-2021 Cisco Systems, Inc.

Exception: multiple definitions for + in body (library (bug) (export) (import (rnrs base)) (define + (quote plus))) at line 2, char 1 of bug.sls
@LiberalArtist LiberalArtist changed the title Identifier incorrectly allowed to be "both imported and defined" Identifier incorrectly allowed to be "both defined and imported" May 22, 2022
@LiberalArtist
Copy link
Contributor Author

It looks like racket/racket@163b9dd might be a simple way to fix this.

@LiberalArtist
Copy link
Contributor Author

I think this incorrectly-accepted program illustrates the same bug, but I am not sure that (#%declare #:require=define) would be enough to fix it:

#!r6rs
(library (conflict)
  (export let)
  (import (for (only (rnrs base) define-syntax lambda) run)
          (for (rnrs base) expand) ; should require (except (rnrs base) let)
          (for (rnrs syntax-case) expand))
  (define-syntax let
    (lambda (stx)
      (syntax-case stx ()
        [(_ id rhs body0 body ...)
         #'((lambda (id) body0 body ...) rhs)]))))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant