Skip to content

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

Merged
merged 1 commit into from
Nov 30, 2020

Conversation

nicolasstucki
Copy link
Contributor

No description provided.

@nicolasstucki nicolasstucki self-assigned this Nov 27, 2020
@nicolasstucki nicolasstucki marked this pull request as ready for review November 27, 2020 15:00
@nicolasstucki nicolasstucki added this to the 3.0.0-RC1 milestone Nov 27, 2020
case _ => "not matched"
}
'{ println(${Expr(res)}) }
}
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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 👍

Copy link
Contributor

@liufengyun liufengyun left a 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)}) }
}
Copy link
Contributor

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 👍

@nicolasstucki nicolasstucki merged commit 0a0b110 into scala:master Nov 30, 2020
@nicolasstucki nicolasstucki deleted the fix-#10464 branch November 30, 2020 12:10
Copy link
Contributor

@LPTK LPTK left a 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)
Copy link
Contributor

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.

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.

4 participants