File tree 5 files changed +55
-5
lines changed
compiler/src/dotty/tools/dotc
5 files changed +55
-5
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ object Printers {
7
7
}
8
8
9
9
object noPrinter extends Printer {
10
- inline override def println (inline msg : => String ): Unit = ()
10
+ inline override def println (msg : => String ): Unit = ()
11
11
}
12
12
13
13
val default = new Printer
Original file line number Diff line number Diff line change @@ -451,7 +451,8 @@ object Checking {
451
451
|| sym.is(TermParam ) && ! sym.owner.isInlineMethod
452
452
))
453
453
fail(ParamsNoInline (sym.owner))
454
-
454
+ if sym.isInlineMethod && ! sym.is(Deferred ) && sym.allOverriddenSymbols.nonEmpty then
455
+ checkInlineOverrideParameters(sym)
455
456
if (sym.isOneOf(GivenOrImplicit )) {
456
457
if (sym.owner.is(Package ))
457
458
fail(TopLevelCantBeImplicit (sym))
@@ -646,6 +647,20 @@ object Checking {
646
647
val enumCls = enumCase.owner.linkedClass
647
648
if ! cls.info.parents.exists(_.typeSymbol == enumCls) then
648
649
ctx.error(i " enum case does not extend its enum $enumCls" , enumCase.sourcePos)
650
+
651
+ /** Check the inline override methods only use inline parameters if they override an inline parameter. */
652
+ def checkInlineOverrideParameters (sym : Symbol )(using Context ): Unit =
653
+ lazy val params = sym.paramSymss.flatten
654
+ for
655
+ sym2 <- sym.allOverriddenSymbols
656
+ (p1, p2) <- sym.paramSymss.flatten.lazyZip(sym2.paramSymss.flatten)
657
+ if p1.is(Inline ) != p2.is(Inline )
658
+ do
659
+ ctx.error(
660
+ if p2.is(Inline ) then " Cannot override inline parameter with a non-inline parameter"
661
+ else " Cannot override non-inline parameter with an inline parameter" ,
662
+ p1.sourcePos)
663
+
649
664
}
650
665
651
666
trait Checking {
Original file line number Diff line number Diff line change
1
+
2
+
3
+ abstract class Logger {
4
+ def log1 (msg : String ): Unit
5
+ inline def log2 (msg : String ): Unit
6
+ inline def log3 (inline msg : String ): Unit
7
+ }
8
+
9
+ class Logger1 extends Logger {
10
+ inline def log1 (msg : String ): Unit = ()
11
+ inline def log2 (msg : String ): Unit = ()
12
+ inline def log3 (msg : String ): Unit = () // error: Cannot override inline parameter with a non-inline parameter
13
+ }
14
+
15
+ class Logger2 extends Logger {
16
+ inline def log1 (inline msg : String ): Unit = () // error: Cannot override non-inline parameter with an inline parameter
17
+ inline def log2 (inline msg : String ): Unit = () // error: Cannot override non-inline parameter with an inline parameter
18
+ inline def log3 (inline msg : String ): Unit = ()
19
+ }
20
+
21
+ trait A {
22
+ inline def f (inline a : Int ): Int
23
+ }
24
+
25
+ trait B {
26
+ def f (a : Int ): Int
27
+ }
28
+
29
+ class C extends A , B {
30
+ inline def f (inline a : Int ): Int = 3 // error: Cannot override non-inline parameter with and inline parameter
31
+ }
32
+
33
+ class D extends B , A {
34
+ inline def f (inline a : Int ): Int = 3 // error: Cannot override non-inline parameter with and inline parameter
35
+ }
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ trait Num[T] {
4
4
5
5
object Num {
6
6
class IntNum extends Num [Int ] {
7
- inline def plus (inline x : Int , inline y : Int ): Int = x + y
7
+ inline def plus (x : Int , y : Int ): Int = x + y
8
8
}
9
9
given IntNum
10
10
Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ object TypeLevel {
26
26
27
27
abstract class GenericSum [S ] extends Generic [S ] {
28
28
def ordinal (x : S ): Int
29
- inline def alternative (n : Int ): GenericProduct [_ <: S ]
29
+ inline def alternative (inline n : Int ): GenericProduct [_ <: S ]
30
30
}
31
31
32
32
abstract class GenericProduct [P ] extends Generic [P ] {
@@ -49,7 +49,7 @@ object Lst {
49
49
case x : Cons [_] => 0
50
50
case Nil => 1
51
51
}
52
- inline override def alternative (inline n : Int ) <: GenericProduct [_ <: Lst [T ]] =
52
+ inline def alternative (inline n : Int ) <: GenericProduct [_ <: Lst [T ]] =
53
53
inline n match {
54
54
case 0 => Cons .GenericCons [T ]
55
55
case 1 => Nil .GenericNil
You can’t perform that action at this time.
0 commit comments