Skip to content

Regression in inline matches, inline parameter gets proxied. #13411

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

Closed
rcano opened this issue Aug 28, 2021 · 3 comments · Fixed by #13429
Closed

Regression in inline matches, inline parameter gets proxied. #13411

rcano opened this issue Aug 28, 2021 · 3 comments · Fixed by #13429

Comments

@rcano
Copy link

rcano commented Aug 28, 2021

Compiler version

3.0.2-RC2

Minimized code

public class Constants {
  public static final int A = 0;
  public static final int B = 2;
  public static final int C = 3;
}
class broken {
  sealed trait Foo
  case object A extends Foo
  case object B extends Foo
  case object C extends Foo
  case object D extends Foo

  inline def foo(inline f: Foo) = inline f match {
    case _: A.type => "the letter a"
    case _: B.type => "the letter b"
    case _: C.type => "the letter c"
    case _: D.type => "the letter d"
  }

  inline def thingy(
    depthClampEnable: Boolean = false,
    rasterizerDiscardEnable: Boolean = false,
    polygonMode: Int = 0,
    cullMode: Int = 0,
    frontFace: Int = 0,
    depthBiasEnable: Boolean = false,
    depthBiasConstantFactor: Float = 0,
    depthBiasClamp: Float = 0,
    depthBiasSlopeFactor: Float = 0,
    lineWidth: Float = 0,
    inline f: Foo = A,
  ) = {
    foo(f)
  }

  thingy(polygonMode = Constants.A, cullMode = Constants.B, frontFace = Constants.C, lineWidth = 1.0f)
}

Output

cannot reduce inline match with
 scrutinee:  f$1 : (f$1 : broken.this.Foo @uncheckedVariance)
 patterns :  case this.A:this.A.type
             case this.B:this.B.type
             case this.C:this.C.type
             case this.D:this.D.type

Expectation

It should compile fine, as it did in prior versions

Note

To replicate this bug, several conditions have to be met (I couldn't reproduce it otherwise):

  • the outer method has to have default parameters unspecified when called (if you specify them all then it works)
  • at least one of the specified parameters must come from a java defined symbol. If you define the constants in scala or inline the values, then it works.
@smarter
Copy link
Member

smarter commented Aug 28, 2021

Could you minimize this example to not depend on lwjgl?

@rcano
Copy link
Author

rcano commented Aug 29, 2021

Could you minimize this example to not depend on lwjgl?

done

@nicolasstucki
Copy link
Contributor

nicolasstucki commented Aug 31, 2021

Minimized to

class Foo
class Bar extends Foo

inline def thingy(a: Int = 0, b: Int = 0, inline c: Foo = new Bar) = {
  inline c match {
    case _: Bar =>
  }
}

def x = 1

def test = thingy(b = x)

nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Aug 31, 2021
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Aug 31, 2021
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Sep 2, 2021
dwijnand pushed a commit to dwijnand/scala3 that referenced this issue Sep 2, 2021
olsdavis pushed a commit to olsdavis/dotty that referenced this issue Apr 4, 2022
@Kordyjan Kordyjan added this to the 3.1.1 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants