File tree Expand file tree Collapse file tree 7 files changed +50
-4
lines changed
compiler/src/dotty/tools/dotc/typer Expand file tree Collapse file tree 7 files changed +50
-4
lines changed Original file line number Diff line number Diff line change @@ -1137,12 +1137,9 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
11371137
11381138 val setter = toSetter(lhsCore)
11391139 if setter.isEmpty then reassignmentToVal
1140- else tryEither {
1140+ else
11411141 val assign = untpd.Apply (setter, tree.rhs :: Nil )
11421142 typed(assign, IgnoredProto (pt))
1143- } {
1144- (_, _) => reassignmentToVal
1145- }
11461143 case _ => lhsCore.tpe match {
11471144 case ref : TermRef =>
11481145 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