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 MatchAlias in unrollTupleTypes #19565

Merged
merged 1 commit into from
Jan 30, 2024
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
3 changes: 3 additions & 0 deletions compiler/src/dotty/tools/dotc/inlines/Inlines.scala
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,9 @@ object Inlines:
unrollTupleTypes(tail).map(head :: _)
case tpe: TermRef if tpe.symbol == defn.EmptyTupleModule =>
Some(Nil)
case tpRef: TypeRef => tpRef.info match
Copy link
Contributor

Choose a reason for hiding this comment

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

The fix works, but I am not sure if this is the correct way to handle MatchAliases.

@sjrd could you have a look at this one?

Copy link
Member

Choose a reason for hiding this comment

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

It looks reasonable, although usually we would rather expect

case tpe: AppliedType if tpe.isMatchAlias => ... tpe.tryNormalize ...

It is a bit suspicious that we directly encounter the tycon here, rather than the surrounding AppliedType. What are tpe and tpe.dealias when we get here on the problematic test case?

Copy link
Contributor Author

@EugeneFlesselle EugeneFlesselle Jan 30, 2024

Choose a reason for hiding this comment

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

Yes I noticed that for instance isMatchAlias is defined on AppliedTypes.
But in this case, we have tpe := TypeRef(NoPrefix, Alias) which remains the same after dealias since the info of Alias is not a TypeAlias but a MatchAlias. The case is not covered here:
https://github.com/lampepfl/dotty/blob/997103d818ead17d528d320b01edefb8792579ac/compiler/src/dotty/tools/dotc/core/Types.scala#L1438-L1445

case MatchAlias(alias) => unrollTupleTypes(alias.tryNormalize)
case _ => None
case _ =>
None

Expand Down
8 changes: 8 additions & 0 deletions tests/pos/i19385.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import scala.compiletime.summonAll

inline def f[M <: Tuple]: Unit =
type Alias = Tuple.Map[M, [X] =>> Numeric[X]]
summonAll[Tuple.Map[M, [X] =>> Numeric[X]]] // compiles
summonAll[Alias] // error: Tuple element types must be known at compile time

val y1 = f[(Int, Int)]
Loading