Skip to content

Regression in getkyo/kyo for match types / type inference #22661

Closed as not planned
@WojciechMazur

Description

@WojciechMazur

Based on OpenCB failure in getkyo/kyo

Compiler version

Last good release: 3.6.4-RC1-bin-20241205-c61897d-NIGHTLY
First bad release: 3.6.4-RC1-bin-20241209-1775d0b-NIGHTLY
Affects 3.6.4-RC1
Bisect points to 2f6e60d

Minimized code

opaque type Tag[A] = String

object Record:
  final class ~[Name <: String, Value] private ()
  opaque type AsField[Name <: String, Value] = Field[Name, Value]
  case class Field[Name <: String, Value](name: Name, tag: Tag[Value])

  object AsField:
    def toField[Name <: String, Value](as: AsField[Name, Value]): Field[?, ?] = as

  object AsFieldsInternal:
    private type HasAsField[Field] = Field match
      case Record.~[name, value] => AsField[name, value]

    inline def summonAsField[Fields](using ev: TypeIntersection[Fields]): Set[Field[?, ?]] =
      TypeIntersection.summonAll[Fields, HasAsField].map(Record.AsField.toField).toSet

sealed abstract class TypeIntersection[A]:
  type AsTuple <: Tuple

object TypeIntersection:
  transparent inline def summonAll[A: TypeIntersection, F[_]]: List[F[Any]] = ???

Output

-- [E007] Type Mismatch Error: /Users/wmazur/projects/scala/community-build3/test.scala:18:59 -----------------------------------------------------------------------------------------------
18 |        TypeIntersection.summonAll[Fields, HasAsField].map(Record.AsField.toField).toSet
   |                                                           ^
   |                                                           Found:    (as : Record.AsFieldsInternal.HasAsField[Any])
   |                                                           Required: Record.AsField[Name, Value]
   |
   |                                                           where:    Name  is a type variable with constraint <: String
   |                                                                     Value is a type variable
   |

Expectation

Should probably compile

Metadata

Metadata

Assignees

No one assigned

    Labels

    itype:soundnessSoundness bug (it lets us compile code that crashes at runtime with a ClassCastException)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions