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

Normalize for underlyingClassRef #20259

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1584,7 +1584,8 @@ object Types extends TypeUtils {
else if (tp.symbol.isAliasType) tp.underlying.underlyingClassRef(refinementOK)
else NoType
case tp: AppliedType =>
if (tp.tycon.isLambdaSub) NoType
if tp.isMatchAlias then tp.tryNormalize.underlyingClassRef(refinementOK)
Copy link
Member

@dwijnand dwijnand Apr 24, 2024

Choose a reason for hiding this comment

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

For this and 20258, what if it's a match alias that doesn't normalise, don't you want to cascade to the later cases?

We don't really have an efficient way to do that (&& tp.tryNormalize.exists :-/)

Copy link
Contributor Author

@EugeneFlesselle EugeneFlesselle Apr 25, 2024

Choose a reason for hiding this comment

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

It might be incorrect but I had intentionally not cascaded to the later cases here. I don't think any of them would return something other than NoType on an unreducible match type.

else if (tp.tycon.isLambdaSub) NoType
else tp.superType.underlyingClassRef(refinementOK)
case tp: AnnotatedType =>
tp.parent.underlyingClassRef(refinementOK)
Expand Down
8 changes: 8 additions & 0 deletions tests/pos/i15827b/A_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

case class Foo()

type T = Tuple.Elem[(Foo, Any), 0]
type U = Tuple.Elem[(Any, T), 1]

val _ = new T() // ok
val _ = new U() // ok
3 changes: 3 additions & 0 deletions tests/pos/i15827b/B_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

val _ = new T() // was error
val _ = new U() // was error
Loading