Skip to content

Commit 4146fbd

Browse files
committed
fix error message on setter with wrong type
1 parent 8563571 commit 4146fbd

File tree

6 files changed

+49
-0
lines changed

6 files changed

+49
-0
lines changed

tests/neg/i20338a.check

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-- [E007] Type Mismatch Error: tests/neg/i20338a.scala:10:15 -----------------------------------------------------------
2+
10 | test.field = "hello" // error
3+
| ^^^^^^^
4+
| Found: ("hello" : String)
5+
| Required: Int
6+
|
7+
| longer explanation available when compiling with `-explain`

tests/neg/i20338a.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
object types:
2+
opaque type Struct = Int
3+
val test: Struct = 25
4+
extension (s: Struct)
5+
def field: Int = s
6+
def field_=(other: Int) = ()
7+
8+
@main def hello =
9+
import types.*
10+
test.field = "hello" // error

tests/neg/i20338b.check

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-- [E007] Type Mismatch Error: tests/neg/i20338.scala:10:8 -------------------------------------------------------------
2+
10 | f.x = 42 // error
3+
| ^^
4+
| Found: (42 : Int)
5+
| Required: String
6+
|
7+
| longer explanation available when compiling with `-explain`

tests/neg/i20338b.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Foo(_x: Int)
2+
3+
extension (s: Foo)
4+
def x_=(x: String): Unit = ()
5+
def x: Int = ???
6+
7+
@main
8+
def Test =
9+
val f = Foo(42)
10+
f.x = 42 // error

tests/neg/i20338c.check

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-- [E052] Type Error: tests/neg/i20338c.scala:9:6 ----------------------------------------------------------------------
2+
9 | f.x = 42 // error
3+
| ^^^^^^^^
4+
| Reassignment to val x
5+
|
6+
| longer explanation available when compiling with `-explain`

tests/neg/i20338c.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Foo(val x: Int)
2+
3+
extension (s: Foo)
4+
def x: Int = 43
5+
6+
@main
7+
def Test =
8+
val f = Foo(42)
9+
f.x = 42 // error

0 commit comments

Comments
 (0)