Skip to content
This repository was archived by the owner on Jun 5, 2023. It is now read-only.
This repository was archived by the owner on Jun 5, 2023. It is now read-only.

Don't use reflection for structural types in inline methods #147

@ysthakur

Description

@ysthakur

Currently, this code does not immediately compile:

type Structural = {
  def foo: Int
}
inline def bar[T <: Structural](t: T) = t.foo

The error given is

Found:    (t : T)
Required: Selectable

where:    T is a type in method bar with bounds <: Structural

The following import might fix the problem:
  import reflect.Selectable.reflectiveSelectable

Scastie that includes the import.

However, I don't think there isn't any need for reflection here, since bar is inlined and the actual type of t will be known at the call site. Would it be possible to expand t.foo to just a normal method call instead of using reflection? I don't think it's a major change, but if it is, it would still be nice to have in a future version of Scala.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions