Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sankalpgambhir opened this issue Jul 2, 2024 · 1 comment · May be fixed by #21411
Open
Assignees
Labels
area:transform itype:bug regression This worked in a previous version but doesn't anymore

Comments

@sankalpgambhir
Copy link

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 .

@sankalpgambhir sankalpgambhir added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Jul 2, 2024
@Gedochao Gedochao added area:transform regression This worked in a previous version but doesn't anymore and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Jul 3, 2024
@Gedochao
Copy link
Contributor

Gedochao commented Jul 3, 2024

Happens in Scala 3.3.1+ (all the way to 3.6.0-RC1-bin-20240702-cd8c5ed-NIGHTLY)
Last stable it compiles succesfully with is 3.3.0

@Gedochao Gedochao added stat:needs bisection Need to use nightly builds and git bisect to find out the commit where this issue was introduced and removed stat:needs bisection Need to use nightly builds and git bisect to find out the commit where this issue was introduced labels Jul 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:transform itype:bug regression This worked in a previous version but doesn't anymore
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants