Skip to content

Ycheck that all methods have method type #1205

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 18, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/dotty/tools/dotc/transform/TreeChecker.scala
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,13 @@ class TreeChecker extends Phase with SymTransformer {
tree
}

/** Check that all methods have MethodicType */
def isMethodType(pt: Type)(implicit ctx: Context): Boolean = pt match {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failing tests suggest that you may be missing AnnotatedTypes here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @DarkDimius , AnnotatedType is indeed missing here. But there's something more related to default parameters.

Following generated function for default parameters

    def copy$default$1[a]: a @uncheckedVariance =
      Some.this.x: a @uncheckedVariance

gets following type:

PolyType(List(a), List(TypeBounds(TypeRef(ThisType(TypeRef(NoPrefix,scala)),Nothing), TypeRef(ThisType(TypeRef(NoPrefix,scala)),Any))), AnnotatedType(TypeRef(ThisType(TypeRef(ThisType(TypeRef(NoPrefix,<empty>)),Some)),Some$$a),ConcreteAnnotation(Apply(Select(New(TypeTree[TypeRef(ThisType(TypeRef(NoPrefix,unchecked)),uncheckedVariance)]),<init>),List()))))

Is it valid for methods of default parameters to take a non-method type?

case at: AnnotatedType => isMethodType(at.tpe)
case _: MethodicType => true // MethodType, ExprType, PolyType
case _ => false
}

override def typedIdent(tree: untpd.Ident, pt: Type)(implicit ctx: Context): Tree = {
assert(tree.isTerm || !ctx.isAfterTyper, tree.show + " at " + ctx.phase)
assert(tree.isType || !needsSelect(tree.tpe), i"bad type ${tree.tpe} for $tree # ${tree.uniqueId}")
Expand Down Expand Up @@ -369,7 +376,9 @@ class TreeChecker extends Phase with SymTransformer {
withDefinedSyms(ddef.tparams) {
withDefinedSymss(ddef.vparamss) {
if (!sym.isClassConstructor) assert(isValidJVMMethodName(sym.name), s"${sym.fullName} name is invalid on jvm")
super.typedDefDef(ddef, sym)
val tpdTree = super.typedDefDef(ddef, sym)
assert(isMethodType(sym.info), i"wrong type, expect a method type for ${sym.fullName}, but found: ${sym.info}")
tpdTree
}
}

Expand Down