Skip to content

Wrong error message when using setter extension method with wrong type #20338

@keynmol

Description

@keynmol

Compiler version

3.4.1

Minimized example

//> using scala 3.4.1

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"

Output Error/Warning message

[error] ./test.scala:12:3
[error] Reassignment to val field
[error]   test.field = "hello"
[error]   ^^^^^^^^^^^^^^^^^^^^

Why this Error/Warning was not helpful

I expected there to be any information about type mismatch in the error message.

-explain doesn't help:

[error] Explanation
[error] ===========
[error] You can not assign a new value to field as values can't be changed.
[error] Keep in mind that every statement has a value, so you may e.g. use
[error]   val field = if (condition) 2 else 5
[error] In case you need a reassignable name, you can declare it as
[error] variable
[error]   var field = ...
[error]   test.field = "hello"
[error]   ^^^^^^^^^^^^^^^^^^^^

Metadata

Metadata

Assignees

No one assigned

    Labels

    SpreeSuitable for a future Spreearea:reportingError reporting including formatting, implicit suggestions, etcbetter-errorsIssues concerned with improving confusing/unhelpful diagnostic messagesitype:enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions