@@ -1235,18 +1235,31 @@ object desugar {
12351235 rhsOK(rhs)
12361236 }
12371237
1238+ def checkOpaqueAlias (tree : MemberDef )(using Context ): MemberDef =
1239+ def check (rhs : Tree ): MemberDef = rhs match
1240+ case bounds : TypeBoundsTree if bounds.alias.isEmpty =>
1241+ report.error(i " opaque type must have a right-hand side " , tree.srcPos)
1242+ tree.withMods(tree.mods.withoutFlags(Opaque ))
1243+ case LambdaTypeTree (_, body) => check(body)
1244+ case _ => tree
1245+ if ! tree.mods.is(Opaque ) then tree
1246+ else tree match
1247+ case TypeDef (_, rhs) => check(rhs)
1248+ case _ => tree
1249+
12381250 /** Check that modifiers are legal for the definition `tree`.
12391251 * Right now, we only check for `opaque`. TODO: Move other modifier checks here.
12401252 */
12411253 def checkModifiers (tree : Tree )(using Context ): Tree = tree match {
12421254 case tree : MemberDef =>
12431255 var tested : MemberDef = tree
1244- def checkApplicable (flag : Flag , test : MemberDefTest ): Unit =
1256+ def checkApplicable (flag : Flag , test : MemberDefTest ): MemberDef =
12451257 if (tested.mods.is(flag) && ! test.applyOrElse(tree, (md : MemberDef ) => false )) {
12461258 report.error(ModifierNotAllowedForDefinition (flag), tree.srcPos)
1247- tested = tested.withMods(tested.mods.withoutFlags(flag))
1248- }
1249- checkApplicable(Opaque , legalOpaque)
1259+ tested.withMods(tested.mods.withoutFlags(flag))
1260+ } else tested
1261+ tested = checkOpaqueAlias(tested)
1262+ tested = checkApplicable(Opaque , legalOpaque)
12501263 tested
12511264 case _ =>
12521265 tree
0 commit comments