typed-racket
typed-racket copied to clipboard
#{x : t} should error when x is not a variable
What version of Racket are you using?
8.7
What program did you run?
#{(cons 1 2) : Number}
What should have happened?
It should error, because the syntax for #{x : t} requires x to be a variable. The type appears to be discarded, making it confusing why it's not used. This compounds with the problem that many people mistook #{x : t} for #{e :: t}, so it appears that the annotation doesn't work.
If you got an error message, please include it here.
N/A
Note that this issue originally came up in https://stackoverflow.com/questions/74974840/applying-to-potentially-empty-lists-in-typed-racket
Is there a way to recognize that #{x : t} is not used in a binding position?
No, the syntax is a reader macro so it doesn't know anything about binding. But making it only work on symbols as the first component is easy.