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

Confusing behaviour of abstract contracts #4994

Closed
Antigen-1 opened this issue May 17, 2024 · 1 comment
Closed

Confusing behaviour of abstract contracts #4994

Antigen-1 opened this issue May 17, 2024 · 1 comment

Comments

@Antigen-1
Copy link
Contributor

Antigen-1 commented May 17, 2024

What version of Racket are you using?

> (version)
"8.13.0.3"

What program did you run?

> (module test racket/base
    (require racket/contract)
    (provide (contract-out #:forall (a?)
                           (struct test ((a a?)))))
      
    (struct test (a)))
> (require 'test)
> (test 1)
test: broke its own contract
  not a?: 1
  in: the 1st argument of
      (-> a? test?)
  contract from: top-level
  blaming: top-level
   (assuming the contract is correct)
  at: string:7:10
 [,bt for context]

What should have happened?
The first a? in the contract shown in the error message is in the negative position so that the value 1 should have been accepted anyway and wrapped in an opaque struct.

If you got an error message, please include it here.
The context may be helpful.

> ,bt
test: broke its own contract
  not a?: 1
  in: the 1st argument of
      (-> a? test?)
  contract from: top-level
  blaming: top-level
   (assuming the contract is correct)
  at: string:7:10
  context...:
   /usr/racket/share/racket/collects/racket/contract/private/blame.rkt:350:0: raise-blame-error
   /usr/racket/share/racket/collects/racket/contract/private/arrow-val-first.rkt:486:18
   /usr/racket/share/racket/pkgs/xrepl-lib/xrepl/xrepl.rkt:1573:0
   /usr/racket/share/racket/collects/racket/repl.rkt:11:26

Please include any other relevant details
(test 1 add1) returns an instance of the test structure type in Racket8.12.

Besides, a procedure that is not a structure constructor and is protected by a similar contract works fine.

> (module test racket/base
    (require racket/contract)
    (provide (contract-out #:forall (a?)
                           (test (-> a? any))))
      
    (define (test a) a))
> ,r 'test
> (test 1)
#<a?/∀>
@Antigen-1 Antigen-1 changed the title Confusing error messages on abstract contracts Confusing behaviour of abstract contracts May 17, 2024
@Antigen-1
Copy link
Contributor Author

This error can't be reproduced with Racket 8.13. I will close this issue.

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