Skip to content

Refine criterion when to skip identifiers in pattern constructors #15367

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
Jun 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer

* In addition:
* - if we are in a constructor of a pattern, we ignore all definitions
* which are methods and not accessors (note: if we don't do that
* case x :: xs in class List would return the :: method).
* which are parameterized (including nullary) methods and not accessors
* (note: if we don't do that case x :: xs in class List would return the :: method).
* - Members of the empty package can be accessed only from within the empty package.
* Note: it would be cleaner to never nest package definitions in empty package definitions,
* but then we'd have to give up the fiction that a compilation unit consists of
Expand All @@ -187,9 +187,10 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
* tools, we did not want to take that step.
*/
def qualifies(denot: Denotation): Boolean =
def isRealMethod(sd: SingleDenotation): Boolean =
sd.symbol.is(Method, butNot = Accessor) && !sd.info.isParameterless
reallyExists(denot)
&& (!pt.isInstanceOf[UnapplySelectionProto]
|| denot.hasAltWith(sd => !sd.symbol.is(Method, butNot = Accessor)))
&& (!pt.isInstanceOf[UnapplySelectionProto] || denot.hasAltWith(!isRealMethod(_)))
&& !denot.symbol.is(PackageClass)
&& {
var owner = denot.symbol.maybeOwner
Expand Down
8 changes: 8 additions & 0 deletions tests/pos/i15347.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
object Test:
enum E[T]:
case A(i: Int)

export E.*

def f(x: E[Int]) = x match
case A(i) => i