Skip to content

Dynamic doesn't compile with Typeclass #22158

Closed as not planned
Closed as not planned
@sequencer

Description

@sequencer

Compiler version

3.5.2

Minimized code

import scala.language.dynamics

trait DynamicHello[E] extends Dynamic:
  extension (ref: E)
    def selectDynamic(
      field: String
    ): Any

given DynamicHello[String] with
  extension (ref: String)
    override def selectDynamic(field: String) = s"Hello $field"

// Doesn't compile with error:
// value hello is not a member of String [15:6]
def badHello(str: String) =
  str.hello

// compile, and prove `DynamicHello[String]` does give to `String`
def goodHello(str: String) =
  str.selectDynamic("hello")

Output

[info] compiling 1 Scala source to xxx ...
[error] -- [E008] Not Found Error: Example.scala:15:6
[error] 18 |  str.hello
[error]    |  ^^^^^^^^^
[error]    |  value hello is not a member of String
[error] one error found

May relate to #17106

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions