Skip to content

Abstract type member on object inconsistent compilation error #15931

Closed
@Lasering

Description

@Lasering

Compiler version

3.1.3

Minimized code

sealed trait TP:
  type P

final class Foo extends TP:
  enum P:
    case A, B

object Bar extends TP:
  enum P:
    case A, B, C

// Works
summon[Foo#P <:< TP#P]
val a: TP#P = Foo().P.A

// These fail
summon[Bar.type#P <:< TP#P]
summon[Bar.P <:< TP#P]
val b: TP#P = Bar.P.A

Output

-- Error: -----------------------------------------------------------------------------------------------------------------------------------------------------
17 |summon[Bar.type#P <:< TP#P]
   |                           ^
   |                           Cannot prove that Bar.P <:< TP#P.
-- Error: -----------------------------------------------------------------------------------------------------------------------------------------------------
18 |summon[Bar.P <:< TP#P]
   |                      ^
   |                      Cannot prove that Bar.P <:< TP#P.
-- [E007] Type Mismatch Error: --------------------------------------------------------------------------------------------------------------------------------
19 |val b: TP#P = Bar.P.A
   |              ^^^^^^^
   |              Found:    (Bar.P.A : Bar.P)
   |              Required: TP#P²
   |
   |              where:    P  is a class in object Bar
   |                        P² is a type in trait TP

Expectation

Code should compile.

Scastie link
Discussion at Discord channel

Context

Regardless of the concrete instance of TP I want to:

  • be able to have a value of type TP#P
  • have a function receiving an argument of type TP#P and be able to pass it either an instance of Foo.P or Bar.type.P.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions