Skip to content

Abstract type referred to in Structural Refinement #8563

Open
@bishabosha

Description

@bishabosha

minimized code

on dotty 0.23.x

trait Methodic {
  def one(a: Any): Any
}

class Foo[A, M <: Methodic { def one(a: A): A } ] {
  def foo(m: M, a: A): Any = m.one(a)
}

class MethodicInt extends Methodic {
  def one(a: Any): Any = "UnRefined"
  def one(i: Int): Int = i
}

object Test extends App {
  println(new Foo[Int, MethodicInt].foo(new MethodicInt, 23))
}

Runtime Output

UnRefined

The above shows that the (a: Any): Any overload was chosen and not the refinement that matched A at the callsite

expectation

The refinement Methodic { def one(a: A): A } has a structural overload one and is is against Section 3.2.9 of the Scala Language Specification [as of 18/3/2020]

Within a method declaration in a structural refinement, the type of any value parameter may only refer to type parameters or abstract types that are contained inside the refinement. That is, it must refer either to a type parameter of the method itself, or to a type definition within the refinement. This restriction does not apply to the method's result type.

in Scala 2.13.1 we get this error:

refined.scala:5: error: Parameter type in structural refinement may not refer to an abstract type defined outside that refinement
class Foo[A, M <: Methodic { def one(a: A): A } ] {
                                     ^
one error found

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