diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index a4fe66b932b2..7c0c7519aa3f 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -1077,15 +1077,15 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit } def typedAndTypeTree(tree: untpd.AndTypeTree)(implicit ctx: Context): AndTypeTree = track("typedAndTypeTree") { - val left1 = typed(tree.left) - val right1 = typed(tree.right) + val left1 = checkSimpleKinded(typed(tree.left)) + val right1 = checkSimpleKinded(typed(tree.right)) assignType(cpy.AndTypeTree(tree)(left1, right1), left1, right1) } def typedOrTypeTree(tree: untpd.OrTypeTree)(implicit ctx: Context): OrTypeTree = track("typedOrTypeTree") { val where = "in a union type" - val left1 = checkNotSingleton(typed(tree.left), where) - val right1 = checkNotSingleton(typed(tree.right), where) + val left1 = checkNotSingleton(checkSimpleKinded(typed(tree.left)), where) + val right1 = checkNotSingleton(checkSimpleKinded(typed(tree.right)), where) assignType(cpy.OrTypeTree(tree)(left1, right1), left1, right1) } diff --git a/tests/neg/i3161.scala b/tests/neg/i3161.scala new file mode 100644 index 000000000000..e664359574be --- /dev/null +++ b/tests/neg/i3161.scala @@ -0,0 +1,10 @@ +object UnionTypes { + trait List[A] + class Empty() extends List[Nothing] + class Cons[A](h: A, t: List[A]) extends List[A] + + def test: Unit = { + val list: Cons | Empty = null // error: missing type parameter + val list2: Empty & Cons = ??? // error: missing type parameter + } +}