Skip to content

[cc] inline polymorphic function failed to instantiate its type parameter to capturing type #16978

Open
@yawen-guan

Description

@yawen-guan

Compiler version

3.3.0-RC2

Minimized code

def foo[T](x: T): T = x
inline def inlineFoo[T](x: T): T = x

case class A() {}
case class B(a: {*} A) {}
val a: {*} A = new A()
foo(new B(a)) // passed
inlineFoo(new B(a)) // failed
val b0 = new B(a) 
inlineFoo(b0) // failed
val b1: {a} B = new B(a)
inlineFoo(b1) // passed

Output

-- [E007] Type Mismatch Error: ...
16 |    inlineFoo(new B(a))
   |              ^^^^^^^^
   |              Found:    {a} B{val a²: (a : {*} A)}
   |              Required: B
   |
   |              where:    a  is a value in method main
   |                        a² is a value in class B
   |
   | longer explanation available when compiling with `-explain`
-- [E007] Type Mismatch Error: ...
18 |    inlineFoo(b0)
   |    ^^^^^^^^^^^^^
   |    Found:    (b0 : {a} B{val a²: {a} A})
   |    Required: B
   |
   |    where:    a  is a value in method main
   |              a² is a value in class B
   |----------------------------------------------------------------------------
   |Inline stack trace
   |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   |This location contains code that was inlined from Main.scala:7
 7 |inline def inlineFoo[T](x: T): T = x
   |                                   ^
    ----------------------------------------------------------------------------
   |
   | longer explanation available when compiling with `-explain`
2 errors found

Expectation

I expect this code to pass.

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