Skip to content

Type refinement lost within nested inline methods #19554

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

Open
soronpo opened this issue Jan 28, 2024 · 5 comments
Open

Type refinement lost within nested inline methods #19554

soronpo opened this issue Jan 28, 2024 · 5 comments

Comments

@soronpo
Copy link
Contributor

soronpo commented Jan 28, 2024

Compiler version

v3.4.0-RC3

Minimized code

trait Foo{type Out}
transparent inline def foo: Foo = new Foo{type Out = 1}

abstract class ABox
class Box[T] extends ABox
transparent inline def box: ABox =
  val f = foo
  Box[f.Out]

final val x: Box[1] = box //error

Output

Found:    Box[?]
Required: Box[(1 : Int)]

Expectation

No error.

@soronpo soronpo added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Jan 28, 2024
@soronpo soronpo changed the title Type refinement lost with inline methods Type refinement lost within nested inline methods Jan 28, 2024
@WojciechMazur WojciechMazur added area:typer area:inline and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Jan 29, 2024
@mbovel mbovel added exp:advanced Spree Suitable for a future Spree labels Jan 31, 2024
@dwijnand
Copy link
Member

dwijnand commented Feb 6, 2024

Dupe of #8739 (at a glance)

@EugeneFlesselle
Copy link
Contributor

I believe this is the expected behaviour. inline definitions are not inlined within the body of other inline defs, so when typechecking the body of baz below we infer the type y to be Int:

transparent inline def foo(x: Int): Int = x
transparent inline def bar(x: Int): Int = foo(x)
transparent inline def baz(x: Int): Int =
  val y/*: Int*/ = foo(x)
  y

val x1 = bar(0): 0 // OK
val x2 = baz(0): 0 // Error

@nicolasstucki
Copy link
Contributor

nicolasstucki commented Feb 7, 2024

This is not exactly the same situation as in #8739.

@soronpo
Copy link
Contributor Author

soronpo commented Feb 7, 2024

Dupe of #8739 (at a glance)

I actually replied with a similar minimization on that issue and completely forgot about it 😃. As I mentioned there, I'm constantly hitting this if it's the same issue. This is not a recursive call though.

@nicolasstucki
Copy link
Contributor

It seems that this issue cobined the issue in #8739 and the minimization above and possibly also an extra hurdle with type avoidance.

Notice that { val f = foo; Box[f.Out] } is ascribed with { val f = foo; Box[f.Out]: Box[?] } to avoid the local reference to f.

@mbovel mbovel removed exp:advanced Spree Suitable for a future Spree labels May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants