Skip to content
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

Fix #18407: Ignore Quote/Slice in init checker #18848

Merged
merged 1 commit into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/init/Semantic.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1383,11 +1383,11 @@ object Semantic:
case tpl: Template =>
init(tpl, thisV, klass)

case _: Import | _: Export =>
case _: Import | _: Export | _: Quote | _: Splice | _: QuotePattern | _: SplicePattern =>
Hot

case _ =>
report.warning("[Internal error] unexpected tree" + Trace.show, expr)
report.warning("[Internal error] unexpected tree: " + expr.getClass + ", trace:\n" + Trace.show, expr)
Hot

/** Handle semantics of leaf nodes
Expand Down
4 changes: 4 additions & 0 deletions tests/init/pos/i18407/base_0.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// base_0.scala
trait BaseTest extends AnyFreeSpecLike {
"empty-test" - {} // ok if we comment out this line
}
37 changes: 37 additions & 0 deletions tests/init/pos/i18407/macros_0.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// macros_0.scala
object source {
import scala.quoted._

class Position()

object Position {
def withPosition[T](
fun: Expr[Position => T]
)(using quotes: Quotes, typeOfT: Type[T]): Expr[T] = {
'{
${ fun }.apply(new source.Position())
}
}
}
}

trait AnyFreeSpecLike {
import scala.language.implicitConversions

protected final class FreeSpecStringWrapper(
string: String,
pos: source.Position
) {
def -(fun: => Unit): Unit = fun
}

inline implicit def convertToFreeSpecStringWrapper(
s: String
): FreeSpecStringWrapper = {
${
source.Position.withPosition[FreeSpecStringWrapper]('{
(pos: source.Position) => new FreeSpecStringWrapper(s, pos)
})
}
}
}
4 changes: 4 additions & 0 deletions tests/init/pos/i18407/test_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class MyTest extends BaseTest {
"empty-test" - {}
private val myObject = new {}
}
Loading