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

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

Open
ysthakur opened this issue Nov 6, 2020 · 1 comment
Open

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

ysthakur opened this issue Nov 6, 2020 · 1 comment

Comments

@ysthakur
Copy link

ysthakur commented Nov 6, 2020

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.

@bishabosha
Copy link
Member

bishabosha commented Nov 18, 2020

I think it might be annoying if it is typed as if there exists a real foo method, but then at the call site where it is inlined there is no foo method and it has to be selected structurally, and now there has been no appropriate Selectable conversion supplied to fall back upon

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants