Skip to content

Inline val in inline def does not always get a constant type #8842

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
nicolasstucki opened this issue Apr 30, 2020 · 3 comments
Closed

Inline val in inline def does not always get a constant type #8842

nicolasstucki opened this issue Apr 30, 2020 · 3 comments

Comments

@nicolasstucki
Copy link
Contributor

Minimized code

inline def f(inline x: Int): Unit = {
  inline val twice = x + x
}

def test: Unit = f(3)

Output

-- Error: Foo.scala:7:18 -------------------------------------------------------
7 |def test: Unit = f(3)
  |                 ^^^^
  |                 type of inline must be a known value
  | This location contains code that was inlined from Foo.scala:3

result of Foo.scala after typer:
package <empty> {
  final lazy module val Foo$package: Foo$package$ = new Foo$package$()
  final module class Foo$package$() extends Object(), _root_.scala.Serializable
     {
   this: Foo$package.type =>
    inline def f(inline x: Int): Unit = 
      {
        inline val twice: Int = x.+(x)
        ()
      }:Unit
    def test: Unit = 
      {
        {
          inline val twice: Int = 6
          ()
        }:Unit
      }
  }
}

Expectation

When f is inlined, the type of twice should be 6. Therewise we wont be able to inline this value.

    def test: Unit = 
      {
        {
          inline val twice: 6 = 6
          ()
        }:Unit
      }
@nicolasstucki
Copy link
Contributor Author

Related to #8836

@nicolasstucki
Copy link
Contributor Author

Better regression teest

inline def f(inline x: Int): Unit = {
  inline val twice = x + x
  inline val thrice = twice + x
  val res = thrice
  res
}

def test: Unit = f(3)

@nicolasstucki
Copy link
Contributor Author

Related to #8739

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

1 participant