File tree Expand file tree Collapse file tree 4 files changed +36
-4
lines changed
compiler/src/dotty/tools/dotc/parsing
language-server/src/dotty/tools/languageserver Expand file tree Collapse file tree 4 files changed +36
-4
lines changed Original file line number Diff line number Diff line change @@ -2546,7 +2546,12 @@ object Parsers {
25462546 def localDef (start : Int , implicitMods : Modifiers = EmptyModifiers ): Tree = {
25472547 var mods = defAnnotsMods(localModifierTokens)
25482548 for (imod <- implicitMods.mods) mods = addMod(mods, imod)
2549- defOrDcl(start, mods)
2549+ if (mods.is(Final )) {
2550+ // A final modifier means the local definition is "class-like".
2551+ tmplDef(start, mods)
2552+ } else {
2553+ defOrDcl(start, mods)
2554+ }
25502555 }
25512556
25522557 /** BlockStatSeq ::= { BlockStat semi } [ResultExpr]
Original file line number Diff line number Diff line change @@ -37,11 +37,11 @@ object Memory {
3737 }
3838
3939 def stats (): String = {
40- final val M = 2 << 20
40+ val M = 2 << 20
4141 val runtime = Runtime .getRuntime
4242 def total = runtime.totalMemory / M
4343 def maximal = runtime.maxMemory / M
4444 def free = runtime.freeMemory / M
4545 s " total used memory: $total MB, free: $free MB, maximal available = $maximal MB "
4646 }
47- }
47+ }
Original file line number Diff line number Diff line change 1+ class Test {
2+ def foo = {
3+ final def bar = 1 // error: local def may not be final
4+ final val v = 42 // error: local val may not be final
5+ final var v2 = 100 // error: local var may not be final
6+ final type T = Int // error: local type def may not be final
7+ }
8+
9+ {
10+ final def foo (x : Int ) = x // error: local def may not be final
11+ }
12+
13+ final def foo2 (x : Int ) = x // ok: final allowed in class field
14+
15+ object Foo {
16+ final def foo (x : Int ) = x // ok, but redundant
17+ }
18+
19+ abstract class Bar {
20+ def foo : Int
21+ }
22+
23+ val x = new Bar {
24+ override final def foo = 42 // ok: def is a field
25+ }
26+ }
Original file line number Diff line number Diff line change 22import Macros ._
33
44object Test {
5+ final val y = 5
6+
57 def main (args : Array [String ]): Unit = {
68 println(foo(1 )) // "Some(1)"
79 println(foo(1 + 7 )) // "Some(8)"
8- final val y = 5
910 println(foo(y)) // "Some(5)"
1011 println(foo(y + 1 ))
1112 val x = 4
You can’t perform that action at this time.
0 commit comments