Skip to content

[E008] Not Found Error: fails due to clashing names, but doesn't mention it, nor provides suggestion on how to workaround #23835

@mr-git

Description

@mr-git

Compiler version

3.7.2

Minimized code

//> using scala 3.7.2
import java.nio.charset.StandardCharsets

object syntax: // works (1) if `extension` is moved inside `object Complex` in place of `import syntax.*`
  extension (self: String)
    def bytes: Int = self.getBytes(StandardCharsets.UTF_8).length

final case class Complex(name: String)

object Complex:
  val one = Complex("1")
  import syntax.* // works (1) if `extension`(s) from `syntax` are moved here
  extension (self: Complex)
    // works (2) if name doesn't clash with imported function's name `bytes`, for example `bytes1` is OK
    def bytes: Long = self.name.bytes

import Complex.*
@main def test =
  println(s"size of `Complex`: ${one.bytes}")

Output

-- [E008] Not Found Error: -----------------------------------------------------
8 |    def bytes: Long = self.name.bytes
  |                      ^^^^^^^^^^^^^^^
  |        value bytes is not a member of String.
  |        An extension method was tried, but could not be fully constructed:
  |
  |            Complex.bytes(self.name)
  |
  |            failed with:
  |
  |                Found:    (self.name : String)
  |                Required: Complex
1 error found

Expectation

If compiler found clashing names, in error message with -explain it could suggest to change import syntax.* to given syntax.type = syntax (or the dangerous case given goodies: syntax() from #23830).

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:reportingError reporting including formatting, implicit suggestions, etcbetter-errorsIssues concerned with improving confusing/unhelpful diagnostic messagesitype:enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions