Skip to content

Commit e7f27a1

Browse files
authored
Merge pull request #3915 from dotty-staging/fix-#3900
Fix #3900: add check for inline class parameters
2 parents 5b1b747 + 10a3a08 commit e7f27a1

File tree

6 files changed

+20
-2
lines changed

6 files changed

+20
-2
lines changed

compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ public enum ErrorMessageID {
125125
UnableToEmitSwitchID,
126126
MissingCompanionForStaticID,
127127
PolymorphicMethodMissingTypeInParentID,
128+
ParamsNoInlineID,
128129
;
129130

130131
public int errorNumber() {

compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2069,4 +2069,11 @@ object messages {
20692069
|$rsym does not override any method in $parentSym. Structural refinement does not allow for
20702070
|polymorphic methods."""
20712071
}
2072+
2073+
case class ParamsNoInline(owner: Symbol)(implicit ctx: Context)
2074+
extends Message(ParamsNoInlineID) {
2075+
val kind = "Syntax"
2076+
val msg = hl"""${"inline"} modifier cannot be used for a ${owner.showKind} parameter"""
2077+
val explanation = ""
2078+
}
20722079
}

compiler/src/dotty/tools/dotc/typer/Checking.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,9 @@ object Checking {
341341
if (!ok && !sym.is(Synthetic))
342342
fail(i"modifier `$flag` is not allowed for this definition")
343343

344+
if (sym.is(Inline) && ((sym.is(ParamAccessor) && sym.owner.isClass) || sym.is(TermParam) && sym.owner.isClassConstructor))
345+
fail(ParamsNoInline(sym.owner))
346+
344347
if (sym.is(ImplicitCommon)) {
345348
if (sym.owner.is(Package))
346349
fail(TopLevelCantBeImplicit(sym))

compiler/src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,7 @@ class Namer { typer: Typer =>
925925
}
926926
}
927927

928-
addAnnotations(denot.symbol, original)
928+
addAnnotations(denot.symbol, original)
929929

930930
val selfInfo =
931931
if (self.isEmpty) NoType

tests/neg/i3900.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class Foo(inline val i: Int) // error
2+
case class Foo2(inline val i: Int) // error
3+
class Foo3(inline val i: Int) extends AnyVal // error
4+
trait Foo4(inline val i: Int) // error
5+
class Foo5() {
6+
def this(inline x: Int) = this() // error
7+
}

tests/neg/inlinevals.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ object Test {
77

88
inline inline val twice = 30 // error: repeated modifier
99

10-
class C(inline x: Int, private inline val y: Int) {
10+
class C(inline x: Int, private inline val y: Int) { // error // error
1111
inline val foo: Int // error: abstract member may not be inline
1212
inline def bar: Int // error: abstract member may not be inline
1313
}

0 commit comments

Comments
 (0)