-
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.
Disallow toplevel infix vals, vars, givens, methods and implicits (#1…
…7994) Disallow infix toplevel definitions for anything that is not a `class`, `typealias`, `match type`, `extension method` and a `trait` (and `objects` as well but these are handled in their own PR). Part of #17738 Continuation of #17966 --------- Co-authored-by: Matt Bovel <[email protected]>
- Loading branch information
Showing
4 changed files
with
67 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
-- [E156] Syntax Error: tests/neg/i17738-toplevel-infix.scala:14:10 ---------------------------------------------------- | ||
14 |infix val toplevelVal = ??? // error | ||
| ^ | ||
| Modifier infix is not allowed for this definition | ||
|-------------------------------------------------------------------------------------------------------------------- | ||
| Explanation (enabled by `-explain`) | ||
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| A top-level value cannot be infix. | ||
-------------------------------------------------------------------------------------------------------------------- | ||
-- [E156] Syntax Error: tests/neg/i17738-toplevel-infix.scala:15:10 ---------------------------------------------------- | ||
15 |infix var toplevelVar = ??? // error | ||
| ^ | ||
| Modifier infix is not allowed for this definition | ||
|-------------------------------------------------------------------------------------------------------------------- | ||
| Explanation (enabled by `-explain`) | ||
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| A top-level variable cannot be infix. | ||
-------------------------------------------------------------------------------------------------------------------- | ||
-- [E156] Syntax Error: tests/neg/i17738-toplevel-infix.scala:16:10 ---------------------------------------------------- | ||
16 |infix def toplevelDef = ??? // error | ||
| ^ | ||
| Modifier infix is not allowed for this definition | ||
|-------------------------------------------------------------------------------------------------------------------- | ||
| Explanation (enabled by `-explain`) | ||
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| A top-level method cannot be infix. | ||
-------------------------------------------------------------------------------------------------------------------- | ||
-- [E156] Syntax Error: tests/neg/i17738-toplevel-infix.scala:17:12 ---------------------------------------------------- | ||
17 |infix given toplevelGiven: Int = ??? // error | ||
| ^ | ||
| Modifier infix is not allowed for this definition | ||
|-------------------------------------------------------------------------------------------------------------------- | ||
| Explanation (enabled by `-explain`) | ||
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| A top-level given instance cannot be infix. | ||
-------------------------------------------------------------------------------------------------------------------- | ||
-- [E156] Syntax Error: tests/neg/i17738-toplevel-infix.scala:18:19 ---------------------------------------------------- | ||
18 |infix implicit val toplevelImplicit: Int = ??? // error | ||
| ^ | ||
| Modifier infix is not allowed for this definition | ||
|-------------------------------------------------------------------------------------------------------------------- | ||
| Explanation (enabled by `-explain`) | ||
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
| A top-level value cannot be infix. | ||
-------------------------------------------------------------------------------------------------------------------- |
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,18 @@ | ||
// scalac: -explain | ||
infix type A[b, a] = Nothing | ||
|
||
infix type B[b, a] = b match { | ||
case Int => a | ||
} | ||
|
||
infix class C[A, B] | ||
infix trait D[A, B] | ||
|
||
extension (x: Boolean) | ||
infix def or (y: => Boolean) = x || y | ||
|
||
infix val toplevelVal = ??? // error | ||
infix var toplevelVar = ??? // error | ||
infix def toplevelDef = ??? // error | ||
infix given toplevelGiven: Int = ??? // error | ||
infix implicit val toplevelImplicit: Int = ??? // error |