File tree 7 files changed +50
-4
lines changed
compiler/src/dotty/tools/dotc/typer
7 files changed +50
-4
lines changed Original file line number Diff line number Diff line change @@ -1334,12 +1334,9 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
1334
1334
1335
1335
val setter = toSetter(lhsCore)
1336
1336
if setter.isEmpty then reassignmentToVal
1337
- else tryEither {
1337
+ else
1338
1338
val assign = untpd.Apply (setter, tree.rhs :: Nil )
1339
1339
typed(assign, IgnoredProto (pt))
1340
- } {
1341
- (_, _) => reassignmentToVal
1342
- }
1343
1340
case _ => lhsCore.tpe match {
1344
1341
case ref : TermRef =>
1345
1342
val lhsVal = lhsCore.denot.suchThat(! _.is(Method ))
Original file line number Diff line number Diff line change
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`
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
1
+ -- [E007] Type Mismatch Error: tests/neg/i20338b.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`
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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`
Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments