@@ -263,6 +263,10 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
263
263
case Select (qual, _) => check(qual) // simple select _n
264
264
case Apply (TypeApply (Select (qual, _), _), _) => check(qual) // generic select .apply[T](n)
265
265
266
+ def checkNotPackage (tree : Tree )(using Context ): Unit =
267
+ if tree.symbol.is(Package ) then
268
+ report.error(i " ${tree.symbol} cannot be used as a type " , tree.srcPos)
269
+
266
270
override def transform (tree : Tree )(using Context ): Tree =
267
271
try tree match {
268
272
// TODO move CaseDef case lower: keep most probable trees first for performance
@@ -273,21 +277,25 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
273
277
case None =>
274
278
ctx
275
279
super .transform(tree)(using gadtCtx)
276
- case tree : Ident if ! tree.isType =>
277
- if tree.symbol.is(Inline ) && ! Inliner .inInlineMethod then
278
- ctx.compilationUnit.needsInlining = true
279
- checkNoConstructorProxy(tree)
280
- tree.tpe match {
281
- case tpe : ThisType => This (tpe.cls).withSpan(tree.span)
282
- case _ => tree
283
- }
280
+ case tree : Ident =>
281
+ if tree.isType then
282
+ checkNotPackage(tree)
283
+ tree
284
+ else
285
+ if tree.symbol.is(Inline ) && ! Inliner .inInlineMethod then
286
+ ctx.compilationUnit.needsInlining = true
287
+ checkNoConstructorProxy(tree)
288
+ tree.tpe match {
289
+ case tpe : ThisType => This (tpe.cls).withSpan(tree.span)
290
+ case _ => tree
291
+ }
284
292
case tree @ Select (qual, name) =>
285
293
if tree.symbol.is(Inline ) then
286
294
ctx.compilationUnit.needsInlining = true
287
- if (name.isTypeName) {
295
+ if name.isTypeName then
296
+ checkNotPackage(tree)
288
297
Checking .checkRealizable(qual.tpe, qual.srcPos)
289
298
withMode(Mode .Type )(super .transform(tree))
290
- }
291
299
else
292
300
checkNoConstructorProxy(tree)
293
301
transformSelect(tree, Nil )
0 commit comments