@@ -5,17 +5,6 @@ import scala.quoted._
5
5
6
6
object SyntheticsSupport :
7
7
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
-
19
8
extension (using Quotes )(s : reflect.Symbol )
20
9
def isSyntheticFunc : Boolean =
21
10
import reflect ._
@@ -29,39 +18,32 @@ object SyntheticsSupport:
29
18
import reflect ._
30
19
s.flags.is(Flags .Opaque )
31
20
32
- def isInfix : Boolean = hackIsInfix(s)
33
-
34
21
def getmembers : List [reflect.Symbol ] = hackGetmembers(s)
35
22
36
23
end extension
37
24
38
- def isValidPos (using Quotes )(pos : reflect.Position ) =
39
- if hackExists(pos) then pos.start != pos.end else false
40
-
41
25
def isSyntheticField (using Quotes )(c : reflect.Symbol ) =
42
26
import reflect ._
43
27
c.flags.is(Flags .CaseAccessor ) || (c.flags.is(Flags .Module ) && ! c.flags.is(Flags .Given ))
44
28
45
29
def constructorWithoutParamLists (using Quotes )(c : reflect.ClassDef ): Boolean =
46
- ! isValidPos( c.constructor.pos) || {
30
+ c.constructor.pos.start == c.constructor.pos.end || {
47
31
val end = c.constructor.pos.end
48
32
val typesEnd = c.constructor.leadingTypeParams.lastOption.fold(end - 1 )(_.pos.end)
49
33
val classDefTree = c.constructor.show
50
34
c.constructor.leadingTypeParams.nonEmpty && end <= typesEnd + 1
51
35
}
52
36
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
+
61
43
/* 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
+ */
65
47
private def hackGetmembers (using Quotes )(rsym : reflect.Symbol ): List [reflect.Symbol ] = {
66
48
import reflect ._
67
49
import dotty .tools .dotc
@@ -75,40 +57,3 @@ object SyntheticsSupport:
75
57
sym.asInstanceOf [Symbol ]
76
58
}.toList
77
59
}
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