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

contract-out struct is inconsistent with struct-out #3277

Closed
sorawee opened this issue Jun 29, 2020 · 3 comments
Closed

contract-out struct is inconsistent with struct-out #3277

sorawee opened this issue Jun 29, 2020 · 3 comments
Labels
bug Something isn't working correctly

Comments

@sorawee
Copy link
Collaborator

sorawee commented Jun 29, 2020

#lang racket

(module first racket
  (struct foo (x))
  (provide (contract-out (struct foo ([x boolean?])))))

(module second racket
  (require (only-in (submod ".." first) foo))
  (provide (contract-out (struct foo ([x boolean?])))))

(require 'second)

foo-x

evaluates to the accessor foo-x.

However, the corresponding struct-out fails:

#lang racket

(module first racket
  (struct foo (x))
  (provide (struct-out foo)))

(module second racket
  (require (only-in (submod ".." first) foo))
  (provide (struct-out foo)))

(require 'second)

foo-x

;; struct-out: no binding for structure-type identifier
;;   at: struct:foo
;;   in: (struct-out foo)

It's unclear which one has the desired behavior. Note that struct-out used to have the same behavior as contract-out, but it was changed to the current behavior in 096ec54

@rfindler
Copy link
Member

Just based on the history, it looks like struct-out is right and contract-out is wrong.

Bogdanp pushed a commit to Bogdanp/racket that referenced this issue Jul 1, 2020
@jackfirth jackfirth added the bug Something isn't working correctly label Jul 8, 2020
@mflatt
Copy link
Member

mflatt commented Apr 16, 2021

A note on the difference: A provide can only export bindings that are imported or defined. In the case of struct-out, if it did not complain about struct:foo, then provide would complain. In the case of contract-out, new bindings are created in the providing module by contract-out (to implement the contract), and those bindings can refer to things (via macro expansion) that are not explicitly imported. So, that's why contract-out can export more — because it's really exporting different.

@sorawee
Copy link
Collaborator Author

sorawee commented Apr 16, 2021

Since this seems to work as intended, I will close the issue.

@sorawee sorawee closed this as completed Apr 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly
Projects
None yet
Development

No branches or pull requests

4 participants