diff --git a/compiler/src/dotty/tools/dotc/ast/Desugar.scala b/compiler/src/dotty/tools/dotc/ast/Desugar.scala index 807a532f02d2..787e2ff5c198 100644 --- a/compiler/src/dotty/tools/dotc/ast/Desugar.scala +++ b/compiler/src/dotty/tools/dotc/ast/Desugar.scala @@ -774,7 +774,7 @@ object desugar { * companion object, and the synthetic opaque type member will go into the self type. */ def opaqueAlias(tdef: TypeDef)(implicit ctx: Context): Tree = - if (tdef.rhs.isInstanceOf[TypeBoundsTree]) { + if (lacksDefinition(tdef)) { ctx.error(em"opaque type ${tdef.name} must be an alias type", tdef.sourcePos) tdef.withFlags(tdef.mods.flags &~ Opaque) } diff --git a/tests/neg/i6055.scala b/tests/neg/i6055.scala new file mode 100644 index 000000000000..4c7905e581f6 --- /dev/null +++ b/tests/neg/i6055.scala @@ -0,0 +1,5 @@ +opaque type i0 // error: opaque type must be an alias type +opaque type i2 <: Int // error: opaque type must be an alias type + +opaque type i1[_] // error: opaque type must be an alias type +opaque type x[_] <: Int // error: opaque type must be an alias type