Skip to content
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

nicolasstucki
Copy link
Contributor

@nicolasstucki nicolasstucki commented Apr 8, 2020

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.

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.
@nicolasstucki nicolasstucki self-assigned this Apr 8, 2020

}

def f[T](x: T): T = x
Copy link
Member

@smarter smarter Apr 8, 2020

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 ?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor

@deusaquilus deusaquilus Apr 19, 2020

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.

@nicolasstucki nicolasstucki marked this pull request as ready for review April 8, 2020 14:43
@nicolasstucki nicolasstucki merged commit 4253708 into scala:master Apr 8, 2020
@nicolasstucki nicolasstucki deleted the improve-type-inference-of-quote-pattern-splices branch April 8, 2020 14:46
@deusaquilus
Copy link
Contributor

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?"

@nicolasstucki
Copy link
Contributor Author

It is just an artefact of the current implementation. I'm working on improving this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants