Skip to content

Commit d8d5f32

Browse files
committed
Fix #3161: Check that operands of &, | are simple-kinded
1 parent 7bf86d2 commit d8d5f32

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,15 +1077,15 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
10771077
}
10781078

10791079
def typedAndTypeTree(tree: untpd.AndTypeTree)(implicit ctx: Context): AndTypeTree = track("typedAndTypeTree") {
1080-
val left1 = typed(tree.left)
1081-
val right1 = typed(tree.right)
1080+
val left1 = checkSimpleKinded(typed(tree.left))
1081+
val right1 = checkSimpleKinded(typed(tree.right))
10821082
assignType(cpy.AndTypeTree(tree)(left1, right1), left1, right1)
10831083
}
10841084

10851085
def typedOrTypeTree(tree: untpd.OrTypeTree)(implicit ctx: Context): OrTypeTree = track("typedOrTypeTree") {
10861086
val where = "in a union type"
1087-
val left1 = checkNotSingleton(typed(tree.left), where)
1088-
val right1 = checkNotSingleton(typed(tree.right), where)
1087+
val left1 = checkNotSingleton(checkSimpleKinded(typed(tree.left)), where)
1088+
val right1 = checkNotSingleton(checkSimpleKinded(typed(tree.right)), where)
10891089
assignType(cpy.OrTypeTree(tree)(left1, right1), left1, right1)
10901090
}
10911091

tests/neg/i3161.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
object UnionTypes {
2+
trait List[A]
3+
class Empty() extends List[Nothing]
4+
class Cons[A](h: A, t: List[A]) extends List[A]
5+
6+
def test: Unit = {
7+
val list: Cons | Empty = null // error: missing type parameter
8+
val list2: Empty & Cons = ??? // error: missing type parameter
9+
}
10+
}

0 commit comments

Comments
 (0)