@@ -7,6 +7,7 @@ import core._
7
7
import dotty .tools .dotc .typer .Checking
8
8
import dotty .tools .dotc .typer .Inliner
9
9
import dotty .tools .dotc .typer .VarianceChecker
10
+ import typer .ErrorReporting .errorTree
10
11
import Types ._ , Contexts ._ , Names ._ , Flags ._ , DenotTransformers ._ , Phases ._
11
12
import SymDenotations ._ , StdNames ._ , Annotations ._ , Trees ._ , Scopes ._
12
13
import Decorators ._
@@ -263,6 +264,10 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
263
264
case Select (qual, _) => check(qual) // simple select _n
264
265
case Apply (TypeApply (Select (qual, _), _), _) => check(qual) // generic select .apply[T](n)
265
266
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
+
266
271
override def transform (tree : Tree )(using Context ): Tree =
267
272
try tree match {
268
273
// TODO move CaseDef case lower: keep most probable trees first for performance
@@ -273,21 +278,23 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
273
278
case None =>
274
279
ctx
275
280
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
+ }
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
288
296
Checking .checkRealizable(qual.tpe, qual.srcPos)
289
- withMode(Mode .Type )(super .transform(tree))
290
- }
297
+ withMode(Mode .Type )(super .transform(checkNotPackage(tree)))
291
298
else
292
299
checkNoConstructorProxy(tree)
293
300
transformSelect(tree, Nil )
0 commit comments