diff options
-rw-r--r-- | src/dotty/tools/dotc/core/Types.scala | 11 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/Inferencing.scala | 31 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/Typer.scala | 2 |
3 files changed, 22 insertions, 22 deletions
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala index 93db5d624..64fa4d3ec 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -596,6 +596,17 @@ object Types { def underlyingIfRepeated(implicit ctx: Context): Type = this.translateParameterized(defn.RepeatedParamClass, defn.SeqClass) + /** If this is a (possibly aliased, annotated, and parameterized) reference to + * a class, the class type ref, otherwise NoType. + */ + def underlyingClassRef(implicit ctx: Context): Type = dealias match { + case tp: TypeRef if tp.symbol.isClass => tp + case tp: TypeVar => tp.underlying.underlyingClassRef + case tp: AnnotatedType => tp.underlying.underlyingClassRef + case tp: RefinedType => tp.underlying.underlyingClassRef + case _ => NoType + } + /** A prefix-less termRef to a new skolem symbol that has the given type as info */ def narrow(implicit ctx: Context): TermRef = TermRef(NoPrefix, ctx.newSkolem(this)) diff --git a/src/dotty/tools/dotc/typer/Inferencing.scala b/src/dotty/tools/dotc/typer/Inferencing.scala index c306b07f3..c7151f9f0 100644 --- a/src/dotty/tools/dotc/typer/Inferencing.scala +++ b/src/dotty/tools/dotc/typer/Inferencing.scala @@ -248,21 +248,13 @@ object Inferencing { * class type reference where the class has a companion module, a reference to * that companion module. Otherwise NoType */ - def companionRef(tp: Type)(implicit ctx: Context): Type = tp.dealias match { - case tp: TypeRef if tp.symbol.isClass => + def companionRef(tp: Type)(implicit ctx: Context): Type = tp.underlyingClassRef match { + case tp: TypeRef => val companion = tp.classSymbol.companionModule if (companion.exists) companion.valRef.asSeenFrom(tp.prefix, companion.symbol.owner) - else - NoType - case tp: TypeVar => - companionRef(tp.underlying) - case tp: AnnotatedType => - companionRef(tp.underlying) - case tp: RefinedType => - companionRef(tp.underlying) - case _ => - NoType + else NoType + case _ => NoType } /** Check that type arguments `args` conform to corresponding bounds in `poly` */ @@ -283,16 +275,13 @@ object Inferencing { /** Check that `tp` is a class type with a stable prefix. * @return Underlying class type if type checks out OK, ObjectClass.typeRef if not. */ - def checkClassTypeWithStablePrefix(tp: Type, pos: Position)(implicit ctx: Context): TypeRef = tp.dealias match { - case tp: TypeRef if tp.symbol.isClass => - checkStable(tp.prefix, pos) - tp - case tp: TypeVar => - checkClassTypeWithStablePrefix(tp.underlying, pos) - case tp: AnnotatedType => - checkClassTypeWithStablePrefix(tp.underlying, pos) + def checkClassTypeWithStablePrefix(tp: Type, pos: Position)(implicit ctx: Context): TypeRef = + tp.underlyingClassRef match { + case tp: TypeRef => + checkStable(tp.prefix, pos) + tp case _ => - ctx.error(i"$tp is not a class type", pos) + ctx.error(s"$tp is not a class type", pos) defn.ObjectClass.typeRef } diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala index 016229bc2..4117b0384 100644 --- a/src/dotty/tools/dotc/typer/Typer.scala +++ b/src/dotty/tools/dotc/typer/Typer.scala @@ -123,7 +123,7 @@ class Typer extends Namer with Applications with Implicits { val whyNot = new StringBuffer val addendum = alts foreach (_.isAccessibleFrom(pre, superAccess, whyNot)) - ctx.error(i"$what cannot be accessed in $where.$whyNot") + ctx.error(i"$what cannot be accessed from $pre.$whyNot", pos) ErrorType } else if (d.symbol is TypeParamAccessor) // always dereference type param accessors |