@@ -7,6 +7,7 @@ import core._
77import dotty .tools .dotc .typer .Checking
88import dotty .tools .dotc .typer .Inliner
99import dotty .tools .dotc .typer .VarianceChecker
10+ import typer .ErrorReporting .errorTree
1011import Types ._ , Contexts ._ , Names ._ , Flags ._ , DenotTransformers ._ , Phases ._
1112import SymDenotations ._ , StdNames ._ , Annotations ._ , Trees ._ , Scopes ._
1213import Decorators ._
@@ -263,9 +264,9 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
263264 case Select (qual, _) => check(qual) // simple select _n
264265 case Apply (TypeApply (Select (qual, _), _), _) => check(qual) // generic select .apply[T](n)
265266
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 )
267+ def checkNotPackage (tree : Tree )(using Context ): Tree =
268+ if ! tree.symbol.is(Package ) then tree
269+ else errorTree(tree, i " ${tree.symbol} cannot be used as a type " )
269270
270271 override def transform (tree : Tree )(using Context ): Tree =
271272 try tree match {
@@ -280,7 +281,6 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
280281 case tree : Ident =>
281282 if tree.isType then
282283 checkNotPackage(tree)
283- tree
284284 else
285285 if tree.symbol.is(Inline ) && ! Inliner .inInlineMethod then
286286 ctx.compilationUnit.needsInlining = true
@@ -293,9 +293,8 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
293293 if tree.symbol.is(Inline ) then
294294 ctx.compilationUnit.needsInlining = true
295295 if name.isTypeName then
296- checkNotPackage(tree)
297296 Checking .checkRealizable(qual.tpe, qual.srcPos)
298- withMode(Mode .Type )(super .transform(tree))
297+ withMode(Mode .Type )(super .transform(checkNotPackage( tree) ))
299298 else
300299 checkNoConstructorProxy(tree)
301300 transformSelect(tree, Nil )
0 commit comments