@@ -71,7 +71,8 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
71
71
override def transformPhase (using Context ): Phase = thisPhase.next
72
72
73
73
protected def newTransformer (using Context ): Transformer =
74
- new PostTyperTransformer
74
+ if ctx.compilationUnit.isJava then LimitedChecksTransformer ()
75
+ else PostTyperTransformer ()
75
76
76
77
val superAcc : SuperAccessors = new SuperAccessors (thisPhase)
77
78
val synthMbr : SyntheticMembers = new SyntheticMembers (thisPhase)
@@ -85,6 +86,65 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
85
86
// TODO fill in
86
87
}
87
88
89
+ private def normalizeTypeArgs (tree : TypeApply )(using Context ): TypeApply = tree.tpe match
90
+ case pt : PolyType => // wait for more arguments coming
91
+ tree
92
+ case _ =>
93
+ def decompose (tree : TypeApply ): (Tree , List [Tree ]) = tree.fun match
94
+ case fun : TypeApply =>
95
+ val (tycon, args) = decompose(fun)
96
+ (tycon, args ++ tree.args)
97
+ case _ =>
98
+ (tree.fun, tree.args)
99
+ end decompose
100
+ def reorderArgs (pnames : List [Name ], namedArgs : List [NamedArg ], otherArgs : List [Tree ]): List [Tree ] = pnames match
101
+ case pname :: pnames1 =>
102
+ namedArgs.partition(_.name == pname) match
103
+ case (NamedArg (_, arg) :: _, namedArgs1) =>
104
+ arg :: reorderArgs(pnames1, namedArgs1, otherArgs)
105
+ case _ =>
106
+ val otherArg :: otherArgs1 = otherArgs
107
+ otherArg :: reorderArgs(pnames1, namedArgs, otherArgs1)
108
+ case nil =>
109
+ assert(namedArgs.isEmpty && otherArgs.isEmpty)
110
+ Nil
111
+ end reorderArgs
112
+
113
+ val (tycon, args) = decompose(tree)
114
+ tycon.tpe.widen match
115
+ case tp : PolyType if args.exists(isNamedArg) =>
116
+ val (namedArgs, otherArgs) = args.partition(isNamedArg)
117
+ val args1 = reorderArgs(tp.paramNames, namedArgs.asInstanceOf [List [NamedArg ]], otherArgs)
118
+ TypeApply (tycon, args1).withSpan(tree.span).withType(tree.tpe)
119
+ case _ =>
120
+ tree
121
+
122
+ class LimitedChecksTransformer extends Transformer {
123
+ private def checkAppliedTypes (tree : Tree )(using Context ): Unit = tree match
124
+ case tpt : TypeTree =>
125
+ Checking .checkAppliedTypesIn(tpt)
126
+ case app : AppliedTypeTree =>
127
+ Checking .checkAppliedType(app, EmptyTree )
128
+ case _ =>
129
+
130
+ override def transform (tree : Tree )(using Context ): Tree =
131
+ ctx.debuglog(s " LimitedChecksTransformer.transform( ${tree.show}) " )
132
+ ctx.debuglog(s " -- $tree" )
133
+ tree match
134
+ case Select (qual, name) if name.isTypeName =>
135
+ Checking .checkRealizable(qual.tpe, qual.posd)
136
+ if name.isTypeName then
137
+ super .transform(tree)(using ctx.addMode(Mode .Type ))
138
+ case tree : TypeApply =>
139
+ val TypeApply (fn, args) = normalizeTypeArgs(tree)
140
+ args.foreach(checkAppliedTypes)
141
+ case tree : ValOrDefDef =>
142
+ checkAppliedTypes(tree.tpt)
143
+ case _ =>
144
+ super .transform(tree)
145
+ tree
146
+ }
147
+
88
148
class PostTyperTransformer extends Transformer {
89
149
90
150
private var inJavaAnnot : Boolean = false
@@ -180,41 +240,6 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
180
240
}
181
241
}
182
242
183
- private def normalizeTypeArgs (tree : TypeApply )(using Context ): TypeApply = tree.tpe match {
184
- case pt : PolyType => // wait for more arguments coming
185
- tree
186
- case _ =>
187
- def decompose (tree : TypeApply ): (Tree , List [Tree ]) = tree.fun match {
188
- case fun : TypeApply =>
189
- val (tycon, args) = decompose(fun)
190
- (tycon, args ++ tree.args)
191
- case _ =>
192
- (tree.fun, tree.args)
193
- }
194
- def reorderArgs (pnames : List [Name ], namedArgs : List [NamedArg ], otherArgs : List [Tree ]): List [Tree ] = pnames match {
195
- case pname :: pnames1 =>
196
- namedArgs.partition(_.name == pname) match {
197
- case (NamedArg (_, arg) :: _, namedArgs1) =>
198
- arg :: reorderArgs(pnames1, namedArgs1, otherArgs)
199
- case _ =>
200
- val otherArg :: otherArgs1 = otherArgs
201
- otherArg :: reorderArgs(pnames1, namedArgs, otherArgs1)
202
- }
203
- case nil =>
204
- assert(namedArgs.isEmpty && otherArgs.isEmpty)
205
- Nil
206
- }
207
- val (tycon, args) = decompose(tree)
208
- tycon.tpe.widen match {
209
- case tp : PolyType if args.exists(isNamedArg) =>
210
- val (namedArgs, otherArgs) = args.partition(isNamedArg)
211
- val args1 = reorderArgs(tp.paramNames, namedArgs.asInstanceOf [List [NamedArg ]], otherArgs)
212
- TypeApply (tycon, args1).withSpan(tree.span).withType(tree.tpe)
213
- case _ =>
214
- tree
215
- }
216
- }
217
-
218
243
private object dropInlines extends TreeMap {
219
244
override def transform (tree : Tree )(using Context ): Tree = tree match {
220
245
case Inlined (call, _, expansion) =>
0 commit comments