Skip to content

Is it expected that summonInline seems to return not as precise type as summon? #23134

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
DmytroMitin opened this issue May 11, 2025 · 1 comment
Labels
itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label

Comments

@DmytroMitin
Copy link

Compiler versions

3.7.2-RC1-bin-20250510-f784625-NIGHTLY
3.7.0
3.6.4

Minimized code

trait A:
  inline def foo: Int

given a: A with
  override inline def foo: Int = 1

summon[A]/*(using a)*/.foo // 1
  
/*transparent*/ inline def summonAAndFoo: Int = summonInline[A].foo
  
summonAAndFoo //doesn't compile: Deferred inline method foo in trait A cannot be invoked

Output

summon[A] seems to return an implicit of precise type a.type.
But summonInline[A] seems to return just A upon inlining, that's why Deferred inline method foo in trait A cannot be invoked.

Is this expected behavior?

The output with scalacOptions ++= Seq( "-Xprint-types", "-Vprint:typer"):

//[info]     <<println:((x: Any): Unit)>(
//[info]       <<<<App.a:App.a>:App.a.type>:App.a.type>.foo:=> Int>):Unit>

//[info]     inline def summonAAndFoo: Int =
//[info]       <
//[info]         <<<scala.compiletime.summonInline:([T]: T)>[App.A]:App.A>.foo:
//[info]           (=> Int)>
//[info]        :Int:Int>
//[info]     <<println:((x: Any): Unit)>(<App.summonAAndFoo:=> Int>):Unit>

The output with scalacOptions ++= Seq( "-Xprint-types", "-Vprint:inlining"):

[info]     <<println:((x: Any): Unit)>(<<<1:(1 : Int)> :Int:Int>:Int>):Unit>

[info]     inline def summonAAndFoo: Int =
[info]       <
[info]         <<<scala.compiletime.summonInline:([T]: T)>[App.A]:App.A>.foo:
[info]           (=> Int)>
[info]        :Int:Int>
[info]     <<println:((x: Any): Unit)>(<<<<App.a:App.a>.foo:<error>> :Int:Int>:Int>
[info]       ):Unit>

Expectation

summonAAndFoo should compile and return 1.

Discovered in https://stackoverflow.com/questions/79614883/how-to-call-an-inline-method-from-within-a-scala-3-6-4-macro

@DmytroMitin DmytroMitin added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels May 11, 2025
@readren
Copy link

readren commented May 12, 2025

Shouldn't be a Expr.summonInline method that returns precise type too. That would allow a macro that summons a generic type-class to get a singleton instance and call its transparent inline overriden methods to obtains constants.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label
Projects
None yet
Development

No branches or pull requests

2 participants