-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Labels
area:reportingError reporting including formatting, implicit suggestions, etcError reporting including formatting, implicit suggestions, etcbetter-errorsIssues concerned with improving confusing/unhelpful diagnostic messagesIssues concerned with improving confusing/unhelpful diagnostic messagesitype:enhancement
Description
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
Labels
area:reportingError reporting including formatting, implicit suggestions, etcError reporting including formatting, implicit suggestions, etcbetter-errorsIssues concerned with improving confusing/unhelpful diagnostic messagesIssues concerned with improving confusing/unhelpful diagnostic messagesitype:enhancement