Skip to content

Fix Reflection wildcard abstraction #13154

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

Closed

Conversation

nicolasstucki
Copy link
Contributor

Currently, we are missing in the API the Wildcard concept for case _ => patterns.
These are encoded as term Ident with name _. This tree can be inconsistently
matched by Ident, TypeIdent or WildcardTypeTree. There is also no way to create an Ident(_).

The typed expression can contain non-Term trees: Wildcard, Alternatives, Bind and Unapply.
The solution is to add a TypedTree supertype of Typed that contains a Tree.

Changes

  • WildcardTypeTree does not match Ident(_) if it is a term
  • Add Wildcard type that matches a term Ident(_)
  • Typed only matched if the expr is a Term
  • Add TypedTree

Partial fix of #12188 (rest of the fix in #12200)

extension (self: Typed)
def tree: Tree = self.expr
def tpt: TypeTree = self.tpt
end extension
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mere style question whether the "double end" is desirable? Arguably, both ends on a very short definition? It comes up on the forum and folks look at this source for style guidance. Maybe we need an influencer on twitter to offer style advice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about the general desirability of the "double end". It mostly came from copy-pasting other uses. I used regex find and replace in this file a lot, the explicit end is sometimes useful for that.

I would say the "double end" is useful when we have a large number of extension methods. In that case it makes it easier to see that all the methods are extension methods.

Currently, we are missing in the API the Wildcard concept for `case _ =>` patterns.
These are encoded as term `Ident` with name `_`. This tree can be inconsistently
 matched by `Ident`, `TypeIdent` or `WildcardTypeTree`. There is also no way to create an `Ident(_)`.

The typed expression can contain non-Term trees: Wildcard, Alternatives, Bind and Unapply.
The solution is to add a TypedTree supertype of Typed that contains a Tree.

Changes
* `WildcardTypeTree` does not match `Ident(_)` if it is a term
* Add `Wildcard` type that matches a term `Ident(_)`
* `Typed` only matched if the expr is a `Term`
* Add `TypedTree`

Partial fix of scala#12188
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.

2 participants