typed-racket icon indicating copy to clipboard operation
typed-racket copied to clipboard

#{x : t} should error when x is not a variable

Open sorawee opened this issue 2 years ago • 2 comments

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

sorawee avatar Jan 01 '23 18:01 sorawee

Is there a way to recognize that #{x : t} is not used in a binding position?

sorawee avatar Jan 01 '23 18:01 sorawee

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.

samth avatar Jan 02 '23 12:01 samth