Dotty: inline val class parameter in backend

Created on 24 Jan 2018  路  9Comments  路  Source: lampepfl/dotty

class Foo(inline val i: Int)

emits the following error

Concrete method has no definition: Concrete method has no definition: DefDef(i,List(),List(List()),TypeTree[TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),class Int)],EmptyTree)
one error found
intermediate bug

All 9 comments

I don't think this should compile at all.

I assume that inline should never be used in a class parameter as we cannot ensure that accesses to those field are inlined. @odersky is that the correct semantics.

Should class Foo(inline i: Int) be allowed?

I think not. It is not allowed either. WDYT?

They should not. There is no way to inline the value of i in any of the references of i.

Should inline on secondary constructor parameters be rejected too?

Yes, unless the secondary constructor is inlinable. Can it?

I don't see why a secondary constructor could not be inlined, although I imagine it is not the same mechanism as inlining a normal function call:

class Foo() {
  def this(x: Int) = this()
}

new Foo(1) // inlined to new Foo() ?

I don't think we should support inlining secondary constructors. It's going to be complicated to implement and offers no value.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

odersky picture odersky  路  60Comments

megri picture megri  路  29Comments

lihaoyi picture lihaoyi  路  30Comments

smarter picture smarter  路  40Comments

odersky picture odersky  路  27Comments