-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #10464: Match overridden definitions #10531
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
Conversation
case _ => "not matched" | ||
} | ||
'{ println(${Expr(res)}) } | ||
} |
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.
The subtle semantics in quoted patterns may cause problems.
Maybe the programmer can change to Reflection for such use cases?
Or, instead of quoted patterns, add extractors to support pattern match on Expr[T]
with clear intention and more predictable semantics.
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.
Yes, less common more precise matching can and must be done using reflection.
The intended semantics have not changed (#10464 (comment)), it was just a bug in the implementation.
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.
I see, thanks for the explanation 👍
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.
LGTM
case _ => "not matched" | ||
} | ||
'{ println(${Expr(res)}) } | ||
} |
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.
I see, thanks for the explanation 👍
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.
@nicolasstucki I think the implementation is still incomplete, as it only checks for overridden symbols in one direction!
private def symbolMatch(scrutinee: Symbol, pattern: Symbol)(using Env): Boolean = | ||
scrutinee == pattern | ||
|| summon[Env].get(scrutinee).contains(pattern) | ||
|| scrutinee.allOverriddenSymbols.contains(pattern) |
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.
The semantics still seem incomplete in this implementation.
Consider:
trait A { def foo: Int }
trait B extends A { def foo: Int = 1 }
val e0: Expr[A] = '{ new B }
val e1: Expr[Int] = '{ $e0.foo }
The quoted expression e1
will not match a pattern like '{ ($x: B).foo }
, but it should.
No description provided.