Skip to content

Commit 1e4974a

Browse files
committed
Unguard GADT selection healing
1 parent b65b0f2 commit 1e4974a

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3994,10 +3994,8 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
39943994
gadts.println(i"Trying to heal member selection by GADT-approximating $wtp")
39953995
val gadtApprox = Inferencing.approximateGADT(wtp)
39963996
gadts.println(i"GADT-approximated $wtp ~~ $gadtApprox")
3997-
if pt.isMatchedBy(gadtApprox) then
3998-
gadts.println(i"Member selection healed by GADT approximation")
3999-
tree.cast(gadtApprox)
4000-
else tree
3997+
gadts.println(i"Member selection healed by GADT approximation")
3998+
tree.cast(gadtApprox)
40013999
else if tree.tpe.derivesFrom(defn.PairClass) && !defn.isTupleNType(tree.tpe.widenDealias) then
40024000
// If this is a generic tuple we need to cast it to make the TupleN/ members accessible.
40034001
// This works only for generic tuples of known size up to 22.

tests/pos/i16603.scala

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
trait MyData
2+
3+
object MyData:
4+
extension (m: MyData)
5+
def printIt() = println("hey from my data")
6+
7+
class MyClass:
8+
def sel(s: String): Int = s.hashCode()
9+
10+
enum MyTag[A]:
11+
case MyDataTag extends MyTag[MyData]
12+
case MyClassTag extends MyTag[MyClass]
13+
14+
def callExtension[A](tag: MyTag[A], a:A): Unit =
15+
tag match
16+
case MyTag.MyDataTag => a.printIt()
17+
case MyTag.MyClassTag => a.sel("hi")
18+
19+
def callExtensionDirectly(m: MyData): Unit =
20+
m.printIt()

0 commit comments

Comments
 (0)