Subtyping involving functions with keyword arguments causes TR to make unsound assumptions about argument types
Nobody has claimed this yet.
- Dominant language
- Racket
- Stars
- 575
- Forks
- 106
- Avg merge
- 2h 1m
- Merged PRs (30d)
- 2
Description
For some reason, this typechecks.
(: f (Number [#:y Boolean] -> Number))
(define (f x #:y [y #f] #:z [z 'this-can-be-anything])
(if y "y is truthy" x))
To be clear, this doesn't typecheck if the z argument is removed, and it doesn't typecheck if the default for y is non-false. However, in this case, TR decides that y will always be false for some reason and lets it slide.
This isn't actually a soundness problem in this example if the optimizer is turned on. Instead, it just makes the function always return x, no matter what y is.
> (f 0 #:y #t)
- : Number
0
However, if you disable the optimizer, the soundness problem manifests, as expected.
> (f 0 #:y #t)
- : Number
"y is truthy"
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the reproducer with the optimizer enabled and disabled, focusing on the keyword-argument subtyping and typechecking path. The fix is done when the example no longer permits an unsound return type and a regression test covers the differing optimizer behavior.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100