File tree 3 files changed +55
-3
lines changed
compiler/src/dotty/tools/dotc/typer
3 files changed +55
-3
lines changed Original file line number Diff line number Diff line change @@ -284,10 +284,14 @@ class Namer { typer: Typer =>
284
284
def checkFlags (flags : FlagSet ) =
285
285
if (flags.isEmpty) flags
286
286
else {
287
- val (ok, adapted, kind) = tree match {
288
- case tree : TypeDef => (flags.isTypeFlags, flags.toTypeFlags, " type" )
289
- case _ => (flags.isTermFlags, flags.toTermFlags, " value" )
287
+ val isType = tree match {
288
+ case tree : TypeDef => true
289
+ case tree : DefDef => tree.name.isTypeName
290
+ case _ => false
290
291
}
292
+ val (ok, adapted, kind) =
293
+ if (isType) (flags.isTypeFlags, flags.toTypeFlags, " type" )
294
+ else (flags.isTermFlags, flags.toTermFlags, " value" )
291
295
if (! ok)
292
296
ctx.error(i " modifier(s) ` $flags' incompatible with $kind definition " , tree.pos)
293
297
adapted
Original file line number Diff line number Diff line change
1
+ trait Nat {
2
+ def toInt : Int
3
+ }
4
+
5
+ case object Z extends Nat {
6
+ transparent def toInt = 0
7
+ }
8
+
9
+ case class S [N <: Nat ](n : N ) extends Nat {
10
+ transparent def toInt = n.toInt + 1
11
+ }
12
+
13
+ object Test extends App {
14
+
15
+ type ToNat (n : Int ) <: Nat =
16
+ if n == 0 then Z .type
17
+ else S [ToNat (n - 1 )]
18
+
19
+ type ToNat = Int // error: double definition
20
+ }
Original file line number Diff line number Diff line change
1
+ trait Nat {
2
+ def toInt : Int
3
+ }
4
+
5
+ case object Z extends Nat {
6
+ transparent def toInt = 0
7
+ }
8
+
9
+ case class S [N <: Nat ](n : N ) extends Nat {
10
+ transparent def toInt = n.toInt + 1
11
+ }
12
+
13
+ class C {
14
+ type ToNat = Int
15
+
16
+ type ToNat2 (n : Int ) <: Nat =
17
+ if n == 0 then Z .type
18
+ else S [ToNat2 (n - 1 )]}
19
+
20
+ object Test extends C {
21
+
22
+ override type ToNat (n : Int ) <: Nat = // error: illegal override
23
+ if n == 0 then Z .type
24
+ else S [ToNat (n - 1 )]
25
+
26
+ override type ToNat2 [X ] = X // error: illegal override
27
+
28
+ }
You can’t perform that action at this time.
0 commit comments