Skip to content

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

Closed
@nicolasstucki

Description

@nicolasstucki

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
      }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions