Repository navigation
Fix type argument lost in constraint expressions within generic typea… - #1709
Conversation
bioball
left a comment
There was a problem hiding this comment.
Thanks! In general, this fix looks good.
We need some tests here; add this:
typealias MyList<T> = List(this[0] is T)
foo: MyList<Int> = List("uh oh")Create file at path pkl-core/src/test/files/LanguageSnippetTests/input/types/typeAliasConstraint3.pkl
And then run class org.pkl.core.LanguageSnippetTests to fill in the expected result.
You can either navigate to that class in IntelliJ and click the run button in the gutter, or you can run this command:
./gradlew pkl-core:test --tests 'org.pkl.core.LanguageSnippetTests'
Co-authored-by: Daniel Chao <[email protected]>
…e.java Co-authored-by: Daniel Chao <[email protected]>
…e.java Co-authored-by: Daniel Chao <[email protected]>
|
@bioball Done! Created the test at |
bioball
left a comment
There was a problem hiding this comment.
LGTM; looking for thumbs from @stackoverflow before merging
|
@bioball There was some formatting error in the file |
stackoverflow
left a comment
There was a problem hiding this comment.
Looks good. Thanks for the contribution.
|
@bioball Thank you so much for your guidance, thorough reviews, and for merging my PR. I really appreciate your time and support throughout the process. Also, thank you @stackoverflow for reviewing my changes. |
Description
When using a generic type alias with a constraint such as
every((it) -> it is T), the type argument (for example,Int) was not being substituted into the constraint expression. As a result, theit is Tcheck silently accepted any value instead of performing an actual type check.Fixes #1705
Before
After
Root Cause
it is T) was stored without Truffle's@Childannotation. Consequently, the tree-walking logic responsible for substituting type parameters could not traverse into the lambda body.Fix
@Childso it can be properly traversed and deep-copied during type alias instantiation.Validation
List("uhoh")used asMyList<Int>now correctly produces a type constraint violation error.List(1, 2, 3)used asMyList<Int>continues to pass.typealias MyList = List(every((it) -> it is Int))) continue to work correctly.LanguageSnippetTests,pkl-codegen-java,pkl-codegen-kotlin, andpkl-clitests pass.