-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Improve type inference of quote pattern splices #8695
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
Improve type inference of quote pattern splices #8695
Conversation
Infer higher bound for type splices. This means that when type information is not given the pattern should match all term that could fit in this hole.
|
||
} | ||
|
||
def f[T](x: T): T = x |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
flipBottom
only special-cases Nothing, but the same issue could reoccur with a different bound like >: Null
. I'm not sure how the example above works anyway, when you write:
case '{ println(f($y)) } => y
shouldn't this be expanded to:
case '{ println(f[$t]($y)) } => y
And that way, any println(f[...](...))
call will match, no matter the type argument ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is the current workaround, but it seems hard to expand it while typing it. At some point, this should be tried.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just meant as a patch for a relatively common code pattern. I'm working on the side on implementing the whole pattern desugaring/typing logic which might help us with those tricky expansions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be great! I might have situations with odd types.
It's really great to be able to rely on normal Scala syntactic sugar when doing quoted pattern matching. I am currently in the process of training several students in Scala in order to be able to help me port the Quill parser to Dotty and their first question is "Why can't we depend on all of Scala's type inferencing when matching quoted blocks?" |
It is just an artefact of the current implementation. I'm working on improving this. |
Infer higher bound for type splices. This means that when type information is not given
the pattern should match all terms that could fit in this hole.
These are a source of buggy patterns that look fine but only match when the content is of type
Nothing
(virtually never). This is never the intent of such code.