Skip to content

Commit

Permalink
fix error message on setter with wrong type
Browse files Browse the repository at this point in the history
  • Loading branch information
iusildra committed May 21, 2024
1 parent 8563571 commit 4146fbd
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/neg/i20338a.check
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`
10 changes: 10 additions & 0 deletions tests/neg/i20338a.scala
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
7 changes: 7 additions & 0 deletions tests/neg/i20338b.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- [E007] Type Mismatch Error: tests/neg/i20338.scala:10:8 -------------------------------------------------------------
10 | f.x = 42 // error
| ^^
| Found: (42 : Int)
| Required: String
|
| longer explanation available when compiling with `-explain`
10 changes: 10 additions & 0 deletions tests/neg/i20338b.scala
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
6 changes: 6 additions & 0 deletions tests/neg/i20338c.check
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`
9 changes: 9 additions & 0 deletions tests/neg/i20338c.scala
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

0 comments on commit 4146fbd

Please sign in to comment.