-
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.
Fix error message on setter with wrong type (#20444)
Fixes #20338 Poke @mbovel @nicolasstucki @hamzaremmal @AnotherMedo
- Loading branch information
Showing
7 changed files
with
50 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
-- [E007] Type Mismatch Error: tests/neg/i20338a.scala:10:15 ----------------------------------------------------------- | ||
10 | test.field = "hello" // error | ||
| ^^^^^^^ | ||
| Found: ("hello" : String) | ||
| Required: Int | ||
| | ||
| longer explanation available when compiling with `-explain` |
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,10 @@ | ||
object types: | ||
opaque type Struct = Int | ||
val test: Struct = 25 | ||
extension (s: Struct) | ||
def field: Int = s | ||
def field_=(other: Int) = () | ||
|
||
@main def hello = | ||
import types.* | ||
test.field = "hello" // error |
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,7 @@ | ||
-- [E007] Type Mismatch Error: tests/neg/i20338b.scala:10:8 ------------------------------------------------------------ | ||
10 | f.x = 42 // error | ||
| ^^ | ||
| Found: (42 : Int) | ||
| Required: String | ||
| | ||
| longer explanation available when compiling with `-explain` |
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,10 @@ | ||
class Foo(_x: Int) | ||
|
||
extension (s: Foo) | ||
def x_=(x: String): Unit = () | ||
def x: Int = ??? | ||
|
||
@main | ||
def Test = | ||
val f = Foo(42) | ||
f.x = 42 // error |
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,6 @@ | ||
-- [E052] Type Error: tests/neg/i20338c.scala:9:6 ---------------------------------------------------------------------- | ||
9 | f.x = 42 // error | ||
| ^^^^^^^^ | ||
| Reassignment to val x | ||
| | ||
| longer explanation available when compiling with `-explain` |
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,9 @@ | ||
class Foo(val x: Int) | ||
|
||
extension (s: Foo) | ||
def x: Int = 43 | ||
|
||
@main | ||
def Test = | ||
val f = Foo(42) | ||
f.x = 42 // error |