@@ -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,6 +264,10 @@ 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
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 " )
270+
266271 override def transform (tree : Tree )(using Context ): Tree =
267272 try tree match {
268273 // TODO move CaseDef case lower: keep most probable trees first for performance
@@ -273,21 +278,23 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
273278 case None =>
274279 ctx
275280 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- }
281+ case tree : Ident =>
282+ if tree.isType then
283+ checkNotPackage(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
288296 Checking .checkRealizable(qual.tpe, qual.srcPos)
289- withMode(Mode .Type )(super .transform(tree))
290- }
297+ withMode(Mode .Type )(super .transform(checkNotPackage(tree)))
291298 else
292299 checkNoConstructorProxy(tree)
293300 transformSelect(tree, Nil )
0 commit comments