@@ -1235,18 +1235,31 @@ object desugar {
1235
1235
rhsOK(rhs)
1236
1236
}
1237
1237
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
+
1238
1250
/** Check that modifiers are legal for the definition `tree`.
1239
1251
* Right now, we only check for `opaque`. TODO: Move other modifier checks here.
1240
1252
*/
1241
1253
def checkModifiers (tree : Tree )(using Context ): Tree = tree match {
1242
1254
case tree : MemberDef =>
1243
1255
var tested : MemberDef = tree
1244
- def checkApplicable (flag : Flag , test : MemberDefTest ): Unit =
1256
+ def checkApplicable (flag : Flag , test : MemberDefTest ): MemberDef =
1245
1257
if (tested.mods.is(flag) && ! test.applyOrElse(tree, (md : MemberDef ) => false )) {
1246
1258
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)
1250
1263
tested
1251
1264
case _ =>
1252
1265
tree
0 commit comments