Skip to content

Commit 96e7f7d

Browse files
authored
Merge pull request #4126 from dotty-staging/fix-#4058-2
Fix #4058: Fix two problems with flag combinations
2 parents 2e6e6d3 + 5da7703 commit 96e7f7d

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1839,7 +1839,7 @@ object Parsers {
18391839
val start = in.offset
18401840
var mods = annotsAsMods()
18411841
if (owner.isTypeName) {
1842-
mods = modifiers(start = mods) | ParamAccessor
1842+
mods = addFlag(modifiers(start = mods), ParamAccessor)
18431843
mods =
18441844
atPos(start, in.offset) {
18451845
if (in.token == VAL) {

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

+9-7
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,10 @@ object Checking {
338338
def checkWithDeferred(flag: FlagSet) =
339339
if (sym.is(flag))
340340
fail(AbstractMemberMayNotHaveModifier(sym, flag))
341-
def checkNoConflict(flag1: FlagSet, flag2: FlagSet) =
342-
if (sym.is(allOf(flag1, flag2)))
343-
fail(i"illegal combination of modifiers: `$flag1` and `$flag2` for: $sym")
341+
def checkNoConflict(flag1: FlagSet, flag2: FlagSet, msg: => String) =
342+
if (sym.is(allOf(flag1, flag2))) fail(msg)
343+
def checkCombination(flag1: FlagSet, flag2: FlagSet) =
344+
checkNoConflict(flag1, flag2, i"illegal combination of modifiers: `$flag1` and `$flag2` for: $sym")
344345
def checkApplicable(flag: FlagSet, ok: Boolean) =
345346
if (!ok && !sym.is(Synthetic))
346347
fail(i"modifier `$flag` is not allowed for this definition")
@@ -373,10 +374,11 @@ object Checking {
373374
}
374375
if (sym.isValueClass && sym.is(Trait) && !sym.isRefinementClass)
375376
fail(CannotExtendAnyVal(sym))
376-
checkNoConflict(Final, Sealed)
377-
checkNoConflict(Private, Protected)
378-
checkNoConflict(Abstract, Override)
379-
checkNoConflict(Lazy, Inline)
377+
checkCombination(Final, Sealed)
378+
checkCombination(Private, Protected)
379+
checkCombination(Abstract, Override)
380+
checkCombination(Lazy, Inline)
381+
checkNoConflict(Lazy, ParamAccessor, s"parameter may not be `lazy`")
380382
if (sym.is(Inline)) checkApplicable(Inline, sym.isTerm && !sym.is(Mutable | Module))
381383
if (sym.is(Lazy)) checkApplicable(Lazy, !sym.is(Method | Mutable))
382384
if (sym.isType && !sym.is(Deferred))

tests/neg/i4058.scala

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class A(sealed val a: Int) { // error
2+
sealed lazy val b = 10 // error
3+
}
4+
class B(lazy val a: Int) // error: parameter may not be lazy
5+
class C(abstract val a: Int)// error
6+
class D {
7+
def f(sealed a: Int) = 0 // error
8+
def g(lazy a: Int) = 0 // error
9+
def g(override a: Int) = 0 // error
10+
def g(abstract a: Int) = 0 // error
11+
}
12+
sealed erased class E // error

0 commit comments

Comments
 (0)