Skip to content

Refinement with parent trait super call is refused when class is in a different package #20952

Closed
@sankalpgambhir

Description

@sankalpgambhir

Compiler version

3.5.1-RC1
Observed when upgrading from 3.3.0 to 3.3.1 originally.

Minimized code

package object packer: // the super class needs to be in a different package
  class SuperClass():
    protected val problem: Any = ??? // needs to be protected

class SuperClass():
  protected val problem: Any = ??? // needs to be protected

// type Target = SuperClass        // passes
type Target = packer.SuperClass // error

trait Child extends Target:

  val aliased: problem.type = problem
  type Alias = problem.type

  val newProblem: Any {val prog: problem.type} = ???  // error
  // val newProblem: Any {val prog: Alias} = ???         // passes
  // val newProblem: Any {val prog: aliased.type} = ???  // passes

class ChildImpl extends Target with Child // concrete implementation is needed

There are a few conditions for this we discovered:

  • the super class has to be in a different package
  • the reference to the val has to be in a type refinement
  • the value has to be protected
  • there has to be a concrete implementation

Output

-- Error: Child.scala:20:6 -----------------------------------------------------------------------------
20 |class ChildImpl extends Target with Child // concrete implementation is needed
   |      ^
   |parent trait Child has a super call which binds to the value packer.SuperClass.problem. Super calls can only target methods.
1 error found

Expectation

The type alias, at least, should not change the checks. I'm not entirely sure if the error is expected in the first place.

The check/error was added in #16908 .

Credit

Minimized during a Scala Spree with @EugeneFlesselle . Originally discovered as epfl-lara/inox#210 .

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions