Skip to content

Commit 183be33

Browse files
committed
add more tests
1 parent 825dbdf commit 183be33

File tree

3 files changed

+43
-5
lines changed

3 files changed

+43
-5
lines changed

compiler/src/dotty/tools/dotc/transform/IsInstanceOfChecker.scala

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,8 @@ object Checkable {
7878
debug.println("X : " + X.widen)
7979

8080
!(P1 <:< X.widen) || {
81-
// val syms = maximizeType(P1, Psym.pos, fromScala2x = false)
82-
isFullyDefined(P1, ForceDegree.noBottom)
8381
val P2 = replaceBinderMap.apply(P)
84-
val res = P1 <:< P2
82+
val res = isFullyDefined(P1, ForceDegree.noBottom) && P1 <:< P2
8583
debug.println("P2: " + P2.show)
8684
debug.println("P1 <:< P2 = " + res)
8785
res
@@ -96,7 +94,7 @@ object Checkable {
9694
case defn.ArrayOf(tpE) => checkable(tpE, tpT)
9795
case _ => checkable(defn.AnyType, tpT)
9896
}
99-
case tpe: AppliedType => !isAbstract && isClassDetermined(tpe)(ctx.fresh.setFreshGADTBounds)
97+
case tpe: AppliedType => !isAbstract && isClassDetermined(tpe)
10098
case AndType(tp1, tp2) => checkable(X, tp1) && checkable(X, tp2)
10199
case OrType(tp1, tp2) => checkable(X, tp1) && checkable(X, tp2)
102100
case AnnotatedType(t, an) => an.symbol == defn.UncheckedAnnot || checkable(X, t)

compiler/test/dotty/tools/dotc/CompilationTests.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ class CompilationTests extends ParallelTesting {
190190
compileFile("tests/neg-custom-args/noimports2.scala", defaultOptions.and("-Yno-imports")) +
191191
compileFile("tests/neg-custom-args/i3882.scala", allowDeepSubtypes) +
192192
compileFile("tests/neg-custom-args/i1754.scala", allowDeepSubtypes) +
193-
compileDir("tests/neg-custom-args/isInstanceOf", defaultOptions and "-Xfatal-warnings") +
193+
compileFilesInDir("tests/neg-custom-args/isInstanceOf", defaultOptions and "-Xfatal-warnings") +
194194
compileFile("tests/neg-custom-args/i3627.scala", allowDeepSubtypes)
195195
}.checkExpectedErrors()
196196

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
sealed trait Exp[T]
2+
case class Num(n: Int) extends Exp[Int]
3+
case class Plus(e1: Exp[Int], e2: Exp[Int]) extends Exp[Int]
4+
case class Var[T](name: String) extends Exp[T]
5+
case class Lambda[T, U](x: Var[T], e: Exp[U]) extends Exp[T => U]
6+
case class App[T, U](f: Exp[T => U], e: Exp[T]) extends Exp[U]
7+
8+
abstract class Env { outer =>
9+
def apply[T](x: Var[T]): T
10+
11+
def + [T](xe: (Var[T], T)) = new Env {
12+
def apply[T](x: Var[T]): T =
13+
if (x == xe._1) xe._2.asInstanceOf[T]
14+
else outer(x)
15+
}
16+
}
17+
18+
object Env {
19+
val empty = new Env {
20+
def apply[T](x: Var[T]): T = ???
21+
}
22+
}
23+
24+
object Test {
25+
26+
val exp = App(Lambda(Var[Int]("x"), Plus(Var[Int]("x"), Num(1))), Var[Int]("2"))
27+
28+
def eval[T](e: Exp[T])(env: Env): T = e match {
29+
case Num(n) => n
30+
case Plus(e1, e2) => eval(e1)(env) + eval(e2)(env)
31+
case v: Var[T] => env(v)
32+
case Lambda(x: Var[s], e) => ((y: s) => eval(e)(env + (x -> y)))
33+
case App(f, e) => eval(f)(env)(eval(e)(env))
34+
}
35+
36+
eval(exp)(Env.empty)
37+
38+
def foo(x: Any): Boolean =
39+
x.isInstanceOf[List[String]] // error
40+
}

0 commit comments

Comments
 (0)