@@ -5,17 +5,6 @@ import scala.quoted._
55
66object SyntheticsSupport :
77
8- extension (using Quotes )(t : reflect.TypeRepr )
9-
10- def isCompiletimeAppliedType : Boolean = t.hackIsCompiletimeAppliedType(t)
11-
12- private def hackIsCompiletimeAppliedType (rtpe : reflect.TypeRepr ): Boolean =
13- import dotty .tools .dotc
14- given ctx : dotc.core.Contexts .Context = quotes.asInstanceOf [scala.quoted.runtime.impl.QuotesImpl ].ctx
15- val tpe = rtpe.asInstanceOf [dotc.core.Types .Type ]
16- ctx.definitions.isCompiletimeAppliedType(tpe.typeSymbol)
17- end extension
18-
198 extension (using Quotes )(s : reflect.Symbol )
209 def isSyntheticFunc : Boolean =
2110 import reflect ._
@@ -29,39 +18,32 @@ object SyntheticsSupport:
2918 import reflect ._
3019 s.flags.is(Flags .Opaque )
3120
32- def isInfix : Boolean = hackIsInfix(s)
33-
3421 def getmembers : List [reflect.Symbol ] = hackGetmembers(s)
3522
3623 end extension
3724
38- def isValidPos (using Quotes )(pos : reflect.Position ) =
39- if hackExists(pos) then pos.start != pos.end else false
40-
4125 def isSyntheticField (using Quotes )(c : reflect.Symbol ) =
4226 import reflect ._
4327 c.flags.is(Flags .CaseAccessor ) || (c.flags.is(Flags .Module ) && ! c.flags.is(Flags .Given ))
4428
4529 def constructorWithoutParamLists (using Quotes )(c : reflect.ClassDef ): Boolean =
46- ! isValidPos( c.constructor.pos) || {
30+ c.constructor.pos.start == c.constructor.pos.end || {
4731 val end = c.constructor.pos.end
4832 val typesEnd = c.constructor.leadingTypeParams.lastOption.fold(end - 1 )(_.pos.end)
4933 val classDefTree = c.constructor.show
5034 c.constructor.leadingTypeParams.nonEmpty && end <= typesEnd + 1
5135 }
5236
53- // TODO: #49 Remove it after TASTY-Reflect release with published flag Extension
54- private def hackIsInfix (using Quotes )(rsym : reflect.Symbol ): Boolean = {
55- import reflect ._
56- import dotty .tools .dotc
57- given ctx : dotc.core.Contexts .Context = quotes.asInstanceOf [scala.quoted.runtime.impl.QuotesImpl ].ctx
58- val sym = rsym.asInstanceOf [dotc.core.Symbols .Symbol ]
59- ctx.definitions.isInfix(sym)
60- }
37+ def getSupertypes (using Quotes )(c : reflect.ClassDef ) =
38+ c.symbol.typeRef.baseClasses.map(b => b -> c.symbol.typeRef.baseType(b)).tail
39+
40+ def typeForClass (using Quotes )(c : reflect.ClassDef ): reflect.TypeRepr =
41+ c.symbol.typeRef.appliedTo(c.symbol.typeMembers.filter(_.isTypeParam).map(_.typeRef))
42+
6143 /* We need there to filter out symbols with certain flagsets, because these symbols come from compiler and TASTY can't handle them well.
62- They are valdefs that describe case companion objects and cases from enum.
63- TASTY crashed when calling _.tree on them.
64- */
44+ They are valdefs that describe case companion objects and cases from enum.
45+ TASTY crashed when calling _.tree on them.
46+ */
6547 private def hackGetmembers (using Quotes )(rsym : reflect.Symbol ): List [reflect.Symbol ] = {
6648 import reflect ._
6749 import dotty .tools .dotc
@@ -75,40 +57,3 @@ object SyntheticsSupport:
7557 sym.asInstanceOf [Symbol ]
7658 }.toList
7759 }
78-
79- private def hackGetSupertypes (using Quotes )(rdef : reflect.ClassDef ) = {
80- import reflect ._
81- import dotty .tools .dotc
82- given dotc .core.Contexts .Context = quotes.asInstanceOf [scala.quoted.runtime.impl.QuotesImpl ].ctx
83- val classdef = rdef.asInstanceOf [dotc.ast.tpd.TypeDef ]
84- val ref = classdef.symbol.info.asInstanceOf [dotc.core.Types .ClassInfo ].appliedRef
85- val baseTypes : List [(dotc.core.Symbols .Symbol , dotc.core.Types .Type )] =
86- ref.baseClasses.map(b => b -> ref.baseType(b))
87- baseTypes.asInstanceOf [List [(Symbol , TypeRepr )]]
88- }
89-
90- private def hackExists (using Quotes )(rpos : reflect.Position ) = {
91- import reflect ._
92- import dotty .tools .dotc
93- import dotty .tools .dotc .util .Spans ._
94- given dotc .core.Contexts .Context = quotes.asInstanceOf [scala.quoted.runtime.impl.QuotesImpl ].ctx
95- val pos = rpos.asInstanceOf [dotc.util.SourcePosition ]
96- pos.exists
97- }
98-
99- def getSupertypes (using Quotes )(c : reflect.ClassDef ) = hackGetSupertypes(c).tail
100-
101- def typeForClass (using Quotes )(c : reflect.ClassDef ): reflect.TypeRepr =
102- import reflect ._
103- import dotty .tools .dotc
104- given dotc .core.Contexts .Context = quotes.asInstanceOf [scala.quoted.runtime.impl.QuotesImpl ].ctx
105- val cSym = c.symbol.asInstanceOf [dotc.core.Symbols .Symbol ]
106- cSym.typeRef.appliedTo(cSym.typeParams.map(_.typeRef)).asInstanceOf [TypeRepr ]
107-
108- def memberInfo (using Quotes )(c : reflect.ClassDef , symbol : reflect.Symbol ): reflect.TypeRepr =
109- import reflect ._
110- import dotty .tools .dotc
111- given dotc .core.Contexts .Context = quotes.asInstanceOf [scala.quoted.runtime.impl.QuotesImpl ].ctx
112- typeForClass(c).asInstanceOf [dotc.core.Types .Type ]
113- .memberInfo(symbol.asInstanceOf [dotc.core.Symbols .Symbol ])
114- .asInstanceOf [TypeRepr ]
0 commit comments