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

Exported inline does not generate inline accessors to exported path #14131

Closed
bishabosha opened this issue Dec 17, 2021 · 3 comments · Fixed by #16757
Closed

Exported inline does not generate inline accessors to exported path #14131

bishabosha opened this issue Dec 17, 2021 · 3 comments · Fixed by #16757

Comments

@bishabosha
Copy link
Member

bishabosha commented Dec 17, 2021

Compiler Version

3.1.2-bin-SNAPSHOT @ b3ab102

Minimised Example

class Dog:
  inline given bark(using msg: String = "Woof!"): String = s"bark: $msg"

class Wolf:
  private val dog: Dog = Dog()
  export dog.given

val w = Wolf()
import w.given
summon[String]

Output

-- Error: ----------------------------------------------------------------------
31 |summon[String]
   |              ^
   |value dog cannot be accessed as a member of (Wolf_this : (w : Wolf)) from module class i14020$package$.
   | This location contains code that was inlined from i14020.scala:39
1 error found

Expectation

no error

Originally posted by @bishabosha in #14051 (comment)

@bishabosha bishabosha changed the title issue with inlining default arg of exported inline given wrong access when inlining default arg of exported inline given Dec 17, 2021
@nicolasstucki
Copy link
Contributor

Minimized

class Dog:
  inline def bark: String = "bark: Woof!"

class Wolf:
  private val dog: Dog = Dog()
  export dog.bark

def test = Wolf().bark

@nicolasstucki
Copy link
Contributor

We are missing the generation of an inline accessor for dog when we create the exported method.

class Wolf:
  private val dog: Dog = Dog()
  export dog.bark

after typer is

  class Wolf() extends Object() {
    private[this] val dog: Dog = new Dog()
    export this.dog.bark
    final inline def bark: String = this.dog.bark
  }

but we want the equivalent of

class Wolf:
  private val dog: Dog = Dog()
  inline def bark: String = dog.bark

which after typer is

  class Wolf() extends Object() {
    private[this] val dog: Dog = new Dog()
    inline def bark: String = this.inline$dog.bark:String
    def inline$dog: Dog = this.dog
  }

We are probably missing a call to PrepareInlineable.makeInlineable when generating the export method

@nicolasstucki
Copy link
Contributor

If we change the following code it example compiles but does not pass Ycheck because the inline accessor is not properly added to the class.
https://github.com/lampepfl/dotty/blob/400427db21410b366e4d9b890d73cec15416b632/compiler/src/dotty/tools/dotc/typer/Namer.scala#L1184-L1185

- PrepareInlineable.registerInlineInfo(forwarder, ddef.rhs)
+ PrepareInlineable.registerInlineInfo(forwarder, ddef.rhs)(using ctx.withOwner(forwarder))

@nicolasstucki nicolasstucki changed the title wrong access when inlining default arg of exported inline given exported inline does not generate inline accessors to exported path Apr 29, 2022
@nicolasstucki nicolasstucki changed the title exported inline does not generate inline accessors to exported path Exported inline does not generate inline accessors to exported path Apr 29, 2022
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jan 31, 2023
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jan 31, 2023
odersky added a commit that referenced this issue Feb 12, 2023
* Fix context owner of `PrepareInlineable.registerInlineInfo`. It should
have as owner the inline method (`forwarder` in this case).
* Eagerly compute the inlinable RHS. Because we create the forwarder
already typed, we do not evaluate/force in typer the
`LazyBodyAnnotation` which is what triggers the computation of the
inline accessors. This happened in posttyper which was too late. There
might be a cleaner solution to this problem, maybe forcing the
annotation explicitly.

Fixes #14131
Fixes #16469
@Kordyjan Kordyjan added this to the 3.3.1 milestone Aug 1, 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.

3 participants