Skip to content

GADT reasoning does not work with quotes #15879

Open
@LPTK

Description

@LPTK

Compiler version

3.1.2

Minimized code

import scala.quoted.*

def test(using Quotes) =
  def foo[T](e: Expr[T]): T = e match { case '{ 2 + 2 } => 4 }

Output

[error] -- [E007] Type Mismatch Error:
[error] 21 |    def foo[T](e: Expr[T]): T = e match { case '{ 2 + 2 } => 4 }
[error]    |                                                             ^
[error]    |                                                     Found:    (4 : Int)
[error]    |                                                     Required: T

Expectation

Should work because we know that Int <: T from this pattern. It's analogous to:

abstract class Expr[+E]
case class Add() extends Expr[Int]

def foo[T](e: Expr[T]): T = e match { case D() => 4 }

which does currently work.

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