Skip to content

Commit 9172a96

Browse files
committed
Fix scala#4058: reject sealed and lazy for class parameters in parser
I noticed `sealed` while reviewing `modifiers`.
1 parent bdfe740 commit 9172a96

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1839,7 +1839,16 @@ object Parsers {
18391839
val start = in.offset
18401840
var mods = annotsAsMods()
18411841
if (owner.isTypeName) {
1842-
mods = modifiers(start = mods) | ParamAccessor
1842+
mods = modifiers(start = mods)
1843+
if (mods.is(Lazy))
1844+
syntaxError("`lazy' modifier not allowed here. Use call-by-name parameters instead")
1845+
mods =
1846+
if (mods.is(Sealed)) {
1847+
syntaxError("`sealed' modifier can be used only for classes")
1848+
mods // Adding ParamAccessor would crash
1849+
} else {
1850+
mods | ParamAccessor
1851+
}
18431852
mods =
18441853
atPos(start, in.offset) {
18451854
if (in.token == VAL) {

tests/neg/i4058.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class A(sealed val a: Int) // error
2+
class B(lazy val a: Int) // error
3+
class C(abstract val a: Int) // error

0 commit comments

Comments
 (0)