-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an error message for local final defs
Co-Authored-By: Eugene Flesselle <[email protected]> Co-Authored-By: anna herlihy <[email protected]> Co-Authored-By: Oliver Bračevac <[email protected]>
- Loading branch information
1 parent
0afd2c1
commit cfbace4
Showing
5 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
-- [E200] Syntax Error: tests/neg/17579.scala:5:10 --------------------------------------------------------------------- | ||
5 | final val v1 = 42 // error: final modifier is not allowed on local definitions | ||
| ^^^ | ||
| The final modifier is not allowed on local definitions | ||
-- [E200] Syntax Error: tests/neg/17579.scala:6:15 --------------------------------------------------------------------- | ||
6 | final lazy val v2 = 42 // error: final modifier is not allowed on local definitions | ||
| ^^^ | ||
| The final modifier is not allowed on local definitions | ||
-- [E200] Syntax Error: tests/neg/17579.scala:7:10 --------------------------------------------------------------------- | ||
7 | final def v4 = 42 // error: final modifier is not allowed on local definitions | ||
| ^^^ | ||
| The final modifier is not allowed on local definitions | ||
-- [E200] Syntax Error: tests/neg/17579.scala:8:10 --------------------------------------------------------------------- | ||
8 | final var v5 = 42 // error: final modifier is not allowed on local definitions | ||
| ^^^ | ||
| The final modifier is not allowed on local definitions | ||
-- [E200] Syntax Error: tests/neg/17579.scala:9:10 --------------------------------------------------------------------- | ||
9 | final type Foo = String // error: final modifier is not allowed on local definitions | ||
| ^^^^ | ||
| The final modifier is not allowed on local definitions | ||
-- [E088] Syntax Error: tests/neg/17579.scala:14:10 -------------------------------------------------------------------- | ||
14 | final private val v3 = 42 // error: expected start of definition | ||
| ^^^^^^^ | ||
| Expected start of definition | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
-- [E147] Syntax Warning: tests/neg/17579.scala:19:6 ------------------------------------------------------------------- | ||
19 | final given Object with {} // warning: modifier `final` is redundant for this definition | ||
| ^^^^^ | ||
| Modifier final is redundant for this definition |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
class C: | ||
final var v = 42 // ok | ||
|
||
def f = | ||
final val v1 = 42 // error: final modifier is not allowed on local definitions | ||
final lazy val v2 = 42 // error: final modifier is not allowed on local definitions | ||
final def v4 = 42 // error: final modifier is not allowed on local definitions | ||
final var v5 = 42 // error: final modifier is not allowed on local definitions | ||
final type Foo = String // error: final modifier is not allowed on local definitions | ||
|
||
// We get a different error message here because `private` is also not a | ||
// local modifier token. In the future, we could always parse all tokens and | ||
// then flag those that are not legal at this point. | ||
final private val v3 = 42 // error: expected start of definition | ||
|
||
{ | ||
// No error in this case, because the `given` is translated to a class | ||
// definition, for which `final` is redundant but not illegal. | ||
final given Object with {} // warning: modifier `final` is redundant for this definition | ||
} | ||
|
||
{ | ||
// Also no error in this case, because we can't easily distinguish it from | ||
// the previous case. | ||
final given Object = new Object {} | ||
} |