diff options
author | Adriaan Moors <adriaan.moors@epfl.ch> | 2010-08-10 21:12:13 +0000 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@epfl.ch> | 2010-08-10 21:12:13 +0000 |
commit | 41bfef808702c291d69d5f742628e1304632bdda (patch) | |
tree | 264d080aca6a0e0059d845cb44716d0cab2afba3 /src/compiler/scala/tools/nsc/typechecker/Typers.scala | |
parent | 04c38829b6fdb03ab62ee20ebff6a56c519bb358 (diff) | |
download | scala-41bfef808702c291d69d5f742628e1304632bdda.tar.gz scala-41bfef808702c291d69d5f742628e1304632bdda.tar.bz2 scala-41bfef808702c291d69d5f742628e1304632bdda.zip |
different approach to manifests of type par...
different approach to manifests of type parameters: before, ambiguity was prevented by leaving type inference failures (Nothing was inferred) in the expression that needs an implicit manifest -- we now put these back in undetparams (maybe they will be inferred) and when we need to produce a manifest for an undetermined parameter (it ended up not being inferred), we assume it will get instantiated to Nothing (but for now don't actually reflect that in the SearchResult, as instantiate should take care of that anyway)
see test file for use case that works with this new scheme, but did not work before: the eager instantiation of type params to Nothing before implicit search even got started would indeed prevent ambiguity -- unfortunately it also ruled out valid code like this (where the type parameter is inferred successfully by the time the manifest is needed)
review by odersky
Diffstat (limited to 'src/compiler/scala/tools/nsc/typechecker/Typers.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 381b1ceed3..6b8c2fe0b4 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -804,15 +804,10 @@ trait Typers { self: Analyzer => context.undetparams = context.undetparams ::: tparams1 adapt(tree1 setType restpe.substSym(tparams, tparams1), mode, pt, original) case mt: MethodType if mt.isImplicit && ((mode & (EXPRmode | FUNmode | LHSmode)) == EXPRmode) => // (4.1) - if (!context.undetparams.isEmpty/* && (mode & POLYmode) == 0 disabled to make implicits in new collection work; we should revisit this. */) { // (9) - // println("adapt IMT: "+(context.undetparams, pt)) //@MDEBUG - context.undetparams = inferExprInstance( - tree, context.extractUndetparams(), pt, mt.params exists (p => isManifest(p.tpe))) - // if we are looking for a manifest, instantiate type to Nothing anyway, - // as we would get amnbiguity errors otherwise. Example - // Looking for a manifest of Nil: This mas many potential types, - // so we need to instantiate to minimal type List[Nothing]. - } + if (context.undetparams nonEmpty) // (9) -- should revisit dropped condition `(mode & POLYmode) == 0` + // dropped so that type args of implicit method are inferred even if polymorphic expressions are allowed + // needed for implicits in 2.8 collection library -- maybe once #3346 is fixed, we can reinstate the condition? + context.undetparams = inferExprInstance(tree, context.extractUndetparams(), pt, false) // false: retract Nothing's that indicate failure, ambiguities in manifests are dealt with in manifestOfType val typer1 = constrTyperIf(treeInfo.isSelfOrSuperConstrCall(tree)) if (original != EmptyTree && pt != WildcardType) typer1.silent(tpr => tpr.typed(tpr.applyImplicitArgs(tree), mode, pt)) match { |