-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Typer regression in multiple Open CB projects #17434
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Reproducer for #macros.scala
trait NameOf:
transparent inline def nameOf(inline expr: Any): String = ${NameOfImpl.nameOf('expr)}
transparent inline def nameOf[T](inline expr: T => Any): String = ${NameOfImpl.nameOf('expr)}
object NameOf extends NameOf
import scala.compiletime.*
import scala.annotation.tailrec
import scala.quoted.*
object NameOfImpl {
def nameOf(expr: Expr[Any])(using Quotes): Expr[String] = {
import quotes.reflect.*
@tailrec def extract(tree: Tree): String = tree match {
case Ident(name) => name
case Select(_, name) => name
case Block(List(stmt), term) => extract(stmt)
case DefDef("$anonfun", _, _, Some(term)) => extract(term)
case Block(_, term) => extract(term)
case Apply(term, _) if term.symbol.fullName != "<special-ops>.throw" => extract(term)
case TypeApply(term, _) => extract(term)
case Inlined(_, _, term) => extract(term)
case Typed(term, _) => extract(term)
case _ => throw new MatchError(s"Unsupported expression: ${expr.show}")
}
val name = extract(expr.asTerm)
Expr(name)
}
} # test.scala
import NameOf._
def test() =
def func1(x: Int): String = ???
val funcVal = func1 _
assert(nameOf(funcVal) == "funcVal")
assert(nameOf(func1 _) == "func1") Output-- [E007] Type Mismatch Error: /workspace/bisect/test.scala:7:18 ---------------
7 | assert(nameOf(funcVal) == "funcVal")
| ^^^^^^^
| Found: (funcVal : Int => String)
| Required: T => Any
|
| longer explanation available when compiling with `-explain`
-- [E007] Type Mismatch Error: /workspace/bisect/test.scala:8:18 ---------------
8 | assert(nameOf(func1 _) == "func1")
| ^^^^^
| Found: Int => String
| Required: T => Any
|
| longer explanation available when compiling with `-explain` Last good release: 3.3.1-RC1-bin-20230501-1aa3372-NIGHTLY Further bisect based commit was not possible due to problems with very strange compile errors not related to that issue, run following command to see the list of potential commits: git log 1aa3372..dee0065 @nicolasstucki @smarter I can see that most of potential commits that could introduce that regression was commit by you. Can you please take a look at that code snippet? |
The reproducer for // macro.scala
import scala.quoted.*
object SelectDynamicMacroImpl {
def selectImpl[E: Type](
ref: Expr[SQLSyntaxProvider[_]],
name: Expr[String]
)(using Quotes): Expr[SQLSyntax] = '{SQLSyntax("foo")}
} // test.scala
import scala.language.dynamics
trait SQLSyntaxProvider[A] extends Dynamic{
def field(name: String): SQLSyntax = ???
inline def selectDynamic(inline name: String): SQLSyntax =
select[A](this, name)
inline def select[E](ref: SQLSyntaxProvider[A], inline name: String): SQLSyntax =
${ SelectDynamicMacroImpl.selectImpl[E]('ref, 'name) }
}
class SQLSyntax(value: String)
trait SQLSyntaxSupport[A]
case class ColumnSQLSyntaxProvider[S <: SQLSyntaxSupport[A], A](support: S) extends SQLSyntaxProvider[A]
case class Account(id: Long, name: String)
object Account extends SQLSyntaxSupport[Account]
def Test() =
val p = ColumnSQLSyntaxProvider[Account.type, Account](Account)
assert(p.name == SQLSyntax("name")) OutputCompiling project (Scala 3.3.1-RC1-bin-20230510-d6c643c-NIGHTLY, JVM)
[error] ./test.scala:22:10
[error] Found: (SQLSyntaxProvider_this : (p : ColumnSQLSyntaxProvider[Account.type, Account]))
[error] Required: SQLSyntaxProvider[A]
[error] assert(p.name == SQLSyntax("name"))
[error] Both reproducers have in common usage of quotes and started to fail in the same commit range |
Bisect points to 5ae7861 |
Minimized import scala.quoted.*
def impl[E: Type](ref: Expr[Foo[_]])(using Quotes): Expr[Unit] = '{ } trait Foo[A]:
inline def foo(): Unit = bar[this.type](this)
inline def bar[E](ref: Foo[A]): Unit = ${ impl[E]('ref) }
def test(p: Foo[Int]) = p.foo() |
Other minimization import scala.quoted.*
inline def foo[T](expr: T => Any): Unit = ${impl('expr)}
def impl(expr: Expr[Any])(using Quotes): Expr[Unit] = '{} def test(f: Int => Any) = foo(f) |
Reverts 5ae7861 Fixes scala#17434
Reverts 5ae7861 Fixes scala#17434
Before 5ae7861 we used to find those types withing the `tpt`. Fixes scala#17434
Before 5ae7861 we used to find those types withing the `tpt`. Fixes scala#17434
Before 5ae7861 we used to find those types withing the `tpt`. Fixes #17434 #### Other CI tests | Project | Version | Build URL | Notes | | ------- | ------- | --------- | ----- | | dwickern/scala-nameof | 4.0.0 | [Open CB logs](https://github.com/VirtusLab/community-build3/actions/runs/5025314096) | passed | | scalikejdbc/scalikejdbc | 4.0.0 | [Open CB logs](https://github.com/VirtusLab/community-build3/actions/runs/5025351221) | passed | | scalikejdbc/scalikejdbc-async | 0.18.0 | [Open CB logs](https://github.com/VirtusLab/community-build3/actions/runs/5025363289) | passed | | bitlap/scalikejdbc-helper | 0.2.3 -> 0.2.6 | [Open CB logs](https://github.com/VirtusLab/community-build3/actions/runs/5025363289) ([old failure](https://github.com/VirtusLab/community-build3/actions/runs/4897105783/jobs/8746001478) | failed with other issue |
Before 5ae7861 we used to find those types withing the `tpt`. Fixes scala#17434
Uh oh!
There was an error while loading. Please reload this page.
Compiler version
3.3.1-RC1-bin-20230504-0e00420-NIGHTLY
Needs minimization based on Open Community Build projects
Output
Example failure from
dwickern/scala-nameof
Expectation
The text was updated successfully, but these errors were encountered: