File tree 3 files changed +26
-4
lines changed
compiler/src/dotty/tools/dotc/ast
3 files changed +26
-4
lines changed Original file line number Diff line number Diff line change @@ -1235,18 +1235,27 @@ object desugar {
1235
1235
rhsOK(rhs)
1236
1236
}
1237
1237
1238
+ def checkOpaqueAlias (tree : MemberDef )(using Context ): MemberDef =
1239
+ if ! tree.mods.is(Opaque ) then tree
1240
+ else tree match
1241
+ case TypeDef (_, bounds : TypeBoundsTree ) if bounds.alias.isEmpty =>
1242
+ report.error(i " opaque type must have a right-hand side " , tree.srcPos)
1243
+ tree.withMods(tree.mods.withoutFlags(Opaque ))
1244
+ case _ => tree
1245
+
1238
1246
/** Check that modifiers are legal for the definition `tree`.
1239
1247
* Right now, we only check for `opaque`. TODO: Move other modifier checks here.
1240
1248
*/
1241
1249
def checkModifiers (tree : Tree )(using Context ): Tree = tree match {
1242
1250
case tree : MemberDef =>
1243
1251
var tested : MemberDef = tree
1244
- def checkApplicable (flag : Flag , test : MemberDefTest ): Unit =
1252
+ def checkApplicable (flag : Flag , test : MemberDefTest ): MemberDef =
1245
1253
if (tested.mods.is(flag) && ! test.applyOrElse(tree, (md : MemberDef ) => false )) {
1246
1254
report.error(ModifierNotAllowedForDefinition (flag), tree.srcPos)
1247
- tested = tested.withMods(tested.mods.withoutFlags(flag))
1248
- }
1249
- checkApplicable(Opaque , legalOpaque)
1255
+ tested.withMods(tested.mods.withoutFlags(flag))
1256
+ } else tested
1257
+ tested = checkOpaqueAlias(tested)
1258
+ tested = checkApplicable(Opaque , legalOpaque)
1250
1259
tested
1251
1260
case _ =>
1252
1261
tree
Original file line number Diff line number Diff line change
1
+ -- [E156] Syntax Error: tests/neg/i15266.scala:5:13 --------------------------------------------------------------------
2
+ 5 |opaque class A // error
3
+ |^^^^^^^^^^^^^^
4
+ |Modifier opaque is not allowed for this definition
5
+ -- Error: tests/neg/i15266.scala:1:12 ----------------------------------------------------------------------------------
6
+ 1 |opaque type Type0 // error
7
+ |^^^^^^^^^^^^^^^^^
8
+ |opaque type must have a right-hand side
Original file line number Diff line number Diff line change
1
+ opaque type Type0 // error
2
+ opaque type Type1 = Int
3
+ opaque type Type2 <: Int = 2
4
+ opaque type Type3 >: 3 <: Int = 3
5
+ opaque class A // error
You can’t perform that action at this time.
0 commit comments