Skip to content

Assert that memberType selects an existing memberType #15161

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

Closed
wants to merge 3 commits into from
Closed
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
1 change: 1 addition & 0 deletions compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1818,6 +1818,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
def termSymbol: Symbol = self.termSymbol
def isSingleton: Boolean = self.isSingleton
def memberType(member: Symbol): TypeRepr =
assert(self.derivesFrom(member.owner), s"$member is not a member of ${self.show}")
member.info.asSeenFrom(self, member.owner)
def baseClasses: List[Symbol] = self.baseClasses
def baseType(cls: Symbol): TypeRepr = self.baseType(cls)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package tests
package exports1
package exports

class A: //unexpected
def aDefInt: Int
Expand All @@ -21,7 +21,7 @@ class A: //unexpected
= ???
def fn[T, U]: T => U
= ???
object Object //expected: val Obj: Object.type
object Object //expected: final val Obj: Object.type
val x: HKT[List, Int] //expected: val x: A.this.HKT[List, Int]
= ???
class Class(val a: Int, val b: Int) extends Serializable //expected: final type Class = a.Class
Expand All @@ -42,4 +42,12 @@ object X: //unexpected
var xVarInt: Int
= 1
var xVar1: 1
= 1
= 1

class B: //unexpected
val a: A
= new A
export a.{Object => Obj, _}
export X._
def obj: Obj.type
= Obj
12 changes: 0 additions & 12 deletions scaladoc-testcases/src/tests/exports2.scala

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,10 @@ trait ClassLikeSupport:
case rhs => rhs
}.map(_.tpe.termSymbol).filter(_.exists).map(_.tree).map {
case v: ValDef if v.symbol.flags.is(Flags.Module) && !v.symbol.flags.is(Flags.Synthetic) =>
v.symbol.owner -> Symbol.newVal(c.symbol, dd.name, v.tpt.tpe, Flags.Final, Symbol.noSymbol).tree
v.symbol.owner -> Symbol.newVal(v.symbol.owner, dd.name, v.tpt.tpe, Flags.Final, Symbol.noSymbol).tree
case other => other.symbol.owner -> other
}.flatMap { (originalOwner, tree) =>
parseMember(c)(tree)
parseMember(originalOwner.tree.asInstanceOf[ClassDef])(tree)
.map { m => m
.withDRI(dd.symbol.dri)
.withName(dd.symbol.normalizedName)
Expand Down Expand Up @@ -324,7 +324,7 @@ trait ClassLikeSupport:

val enumVals = companion.membersToDocument.collect {
case vd: ValDef if !isSyntheticField(vd.symbol) && vd.symbol.flags.is(Flags.Enum) && vd.symbol.flags.is(Flags.Case) => vd
}.toList.map(parseValDef(classDef, _))
}.toList.map(parseValDef(companion, _))

val enumTypes = companion.membersToDocument.collect {
case td: TypeDef if !td.symbol.flags.is(Flags.Synthetic) && td.symbol.flags.is(Flags.Enum) && td.symbol.flags.is(Flags.Case) => td
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ abstract class SignatureTest(
.map { file => Source.fromFile(s"${BuildInfo.test_testcasesSourceRoot}/tests/$file.scala") }
.flatMap(signaturesFromSources(_, signatureKinds))
.toList

val expectedFromSources: Map[String, List[String]] = allSignaturesFromSources
.collect { case e: Expected => e }
.groupMap(_.name)(_.signature)

val unexpectedFromSources: Set[String] = allSignaturesFromSources.collect { case Unexpected(name) => name }.toSet

val actualSignatures: Map[String, Seq[String]] =
Expand Down Expand Up @@ -84,7 +86,7 @@ abstract class SignatureTest(

private def findName(signature: String, kinds: Seq[String]): Option[String] =
for
kindMatch <- kinds.flatMap(k =>s"\\b$k\\b".r.findFirstMatchIn(signature)).headOption
kindMatch <- kinds.flatMap(k => s"\\b$k\\b".r.findFirstMatchIn(signature)).minByOption(_.start)
kind <- Option(kindMatch.group(0)) // to filter out nulls
afterKind <- Option(kindMatch.after(0)) // to filter out nulls
name <- if kind.contains("extension") then Some(signature) // The name of an extension will always be the signature itself
Expand All @@ -98,7 +100,8 @@ abstract class SignatureTest(
.toSeq
.flatMap {
case unexpectedRegex(signature) => findName(signature, kinds).map(Unexpected(_))
case expectedRegex(signature) => findName(signature, kinds).map(Expected(_, signature))
case expectedRegex(signature) =>
findName(signature, kinds).map(Expected(_, signature))
case signature =>
findName(signature, kinds).map(
Expected(_, commentRegex.replaceAllIn(signature, "")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class ContextBounds extends SignatureTest("contextBounds", SignatureTest.all)

class FBoundedTypeParameters extends SignatureTest("fboundedTypeParameters", SignatureTest.all)

class Exports extends SignatureTest("exports2", SignatureTest.all, sourceFiles = List("exports1", "exports2"))
class Exports extends SignatureTest("exports", SignatureTest.all, filterFunc = _.toString.endsWith("B.html"))

class ContextFunctions extends SignatureTest("contextfunctions", SignatureTest.all)

Expand Down
10 changes: 10 additions & 0 deletions tests/neg-macros/i15159/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import scala.quoted.*
object TestMacro:
inline def test[T]: Unit = ${ testImpl[T] }
def testImpl[T: Type](using Quotes): Expr[Unit] =
import quotes.reflect.*
val tpe = TypeRepr.of[T]
tpe.typeSymbol.children.map { childSymbol =>
tpe.memberType(childSymbol) // not a member of tpe
}
'{ () }
6 changes: 6 additions & 0 deletions tests/neg-macros/i15159/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
sealed trait A
case class X(i: Int) extends A

object Test extends App {
TestMacro.test[A] // error
}
2 changes: 1 addition & 1 deletion tests/run-macros/i13230/Macros_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ inline def showEnumChildren = ${ showEnumChildrenExpr }

def showEnumChildrenExpr(using Quotes) =
import quotes.reflect.*
val repr = TypeRepr.of[E]
val repr = TypeRepr.of[E.type] // we know that all the implementations of the class E are in the object E
Expr(TypeRepr.of[E].classSymbol.get.children.map(sym => (sym.name, repr.memberType(sym).show)))

Loading