@@ -263,6 +263,10 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
263263 case Select (qual, _) => check(qual) // simple select _n
264264 case Apply (TypeApply (Select (qual, _), _), _) => check(qual) // generic select .apply[T](n)
265265
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+
266270 override def transform (tree : Tree )(using Context ): Tree =
267271 try tree match {
268272 // TODO move CaseDef case lower: keep most probable trees first for performance
@@ -273,21 +277,25 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
273277 case None =>
274278 ctx
275279 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+ }
284292 case tree @ Select (qual, name) =>
285293 if tree.symbol.is(Inline ) then
286294 ctx.compilationUnit.needsInlining = true
287- if (name.isTypeName) {
295+ if name.isTypeName then
296+ checkNotPackage(tree)
288297 Checking .checkRealizable(qual.tpe, qual.srcPos)
289298 withMode(Mode .Type )(super .transform(tree))
290- }
291299 else
292300 checkNoConstructorProxy(tree)
293301 transformSelect(tree, Nil )
0 commit comments