Skip to content

Commit e80337f

Browse files
dwijnandKordyjan
authored andcommitted
Fix widen types before checking an implicit view exists
It's not possible to convert a method, such as a polymorphic method, such as `makeChurch`, into another type - we need to widen out the TermRef to discover the underlying PolyType which isn't a value type. Failing to do so will create a dummyTreeOfType, which will then be attempted to be applied, which eventually causes an assertion crash while building the tpd.TypeApply. [Cherry-picked 8a2773f]
1 parent cf87092 commit e80337f

File tree

4 files changed

+43
-1
lines changed

4 files changed

+43
-1
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ trait Implicits:
825825
&& !to.isError
826826
&& !ctx.isAfterTyper
827827
&& ctx.mode.is(Mode.ImplicitsEnabled)
828-
&& from.isValueType
828+
&& from.widen.isValueType
829829
&& ( from.isValueSubType(to)
830830
|| inferView(dummyTreeOfType(from), to)
831831
(using ctx.fresh.addMode(Mode.ImplicitExploration).setExploreTyperState()).isSuccess

tests/neg/i18650.min.scala

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class Church[B]:
2+
type Nat = Tuple1[B]
3+
4+
class Test:
5+
given makeChurch[C]: Church[C] = ??? // necessary to cause crash
6+
7+
def churchTest(c: Church[Int]): Unit =
8+
val res1 = summon[c.Nat =:= Int] // error (not a compiler crash)

tests/neg/i18650.min2.scala

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class Church[B]:
2+
type Nat = Tuple1[B]
3+
4+
class Test2:
5+
given makeChurch2[C](using DummyImplicit): Church[C] = ???
6+
7+
def churchTest2(c: Church[Int]): Unit =
8+
val res2 = summon[c.Nat =:= Int] // error (not a compiler crash)

tests/neg/i18650.scala

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
trait Lam:
2+
type F[_]
3+
extension [A, B](f: F[A => B]) def apply(arg: F[A]): F[B]
4+
def lam[A, B](f: F[A] => F[B]): F[A => B]
5+
final def id[A]: F[A => A] = lam(identity[F[A]])
6+
7+
object LamInterpreter extends Lam:
8+
type F[t] = t
9+
def lam[A, B](f: F[A] => F[B]): F[A => B] = f
10+
extension [A, B](f: F[A => B]) def apply(arg: F[A]): F[B] = f(arg)
11+
12+
13+
class Church[A](using val l: Lam):
14+
import l.*
15+
type Nat = F[(A => A) => (A => A)]
16+
def zero: Nat = id
17+
extension (n: Nat) def suc: Nat = lam(f => lam(x => f(n(f)(x))))
18+
19+
given [A](using l: Lam): Church[A] = Church()
20+
21+
22+
@main
23+
def churchTest =
24+
given Lam = LamInterpreter
25+
val c: Church[Int] = summon
26+
summon[c.Nat =:= ((Int => Int) => (Int => Int))] // error (not a compiler crash)

0 commit comments

Comments
 (0)