diff --git a/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala b/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala index 2521ce0b4c4..29c1f0f24bd 100644 --- a/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala +++ b/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala @@ -834,11 +834,6 @@ trait ContextErrors extends splain.SplainErrors { setError(tree) } - def DependentMethodTpeConversionToFunctionError(tree: Tree, tp: Type): Tree = { - issueNormalTypeError(tree, "method with dependent type " + tp + " cannot be converted to function value") - setError(tree) - } - // cases where we do not necessarily return trees //checkStarPatOK diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index e1eed2b8834..d592809fcb9 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -3202,12 +3202,9 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper def typedEtaExpansion(tree: Tree, mode: Mode, pt: Type): Tree = { debuglog(s"eta-expanding $tree: ${tree.tpe} to $pt") - if (tree.tpe.isDependentMethodType) DependentMethodTpeConversionToFunctionError(tree, tree.tpe) // TODO: support this - else { - val expansion = etaExpand(tree, context.owner) - if (context.undetparams.isEmpty) typed(expansion, mode, pt) - else instantiate(typed(expansion, mode), mode, pt) - } + val expansion = etaExpand(tree, context.owner) + if (context.undetparams.isEmpty) typed(expansion, mode, pt) + else instantiate(typed(expansion, mode), mode, pt) } def typedRefinement(templ: Template): Unit = { diff --git a/src/reflect/scala/reflect/internal/Definitions.scala b/src/reflect/scala/reflect/internal/Definitions.scala index ef7a73c8725..44ffcc8e926 100644 --- a/src/reflect/scala/reflect/internal/Definitions.scala +++ b/src/reflect/scala/reflect/internal/Definitions.scala @@ -855,7 +855,7 @@ trait Definitions extends api.StandardDefinitions { | was: $restpe | now""")(methodToExpressionTp(restpe)) case mt @ MethodType(_, restpe) if mt.isImplicit => methodToExpressionTp(restpe) - case mt @ MethodType(_, restpe) if !mt.isDependentMethodType => + case mt @ MethodType(_, restpe) => if (phase.erasedTypes) FunctionClass(mt.params.length).tpe else functionType(mt.paramTypes, methodToExpressionTp(restpe)) case NullaryMethodType(restpe) => methodToExpressionTp(restpe) diff --git a/test/files/neg/error_dependentMethodTpeConversionToFunction.check b/test/files/neg/error_dependentMethodTpeConversionToFunction.check deleted file mode 100644 index 58da78fe945..00000000000 --- a/test/files/neg/error_dependentMethodTpeConversionToFunction.check +++ /dev/null @@ -1,4 +0,0 @@ -error_dependentMethodTpeConversionToFunction.scala:4: error: method with dependent type (x: AnyRef): x.type cannot be converted to function value - val x: Any => Any = foo - ^ -1 error diff --git a/test/files/neg/error_dependentMethodTpeConversionToFunction.scala b/test/files/neg/error_dependentMethodTpeConversionToFunction.scala deleted file mode 100644 index d0c4cb48a8e..00000000000 --- a/test/files/neg/error_dependentMethodTpeConversionToFunction.scala +++ /dev/null @@ -1,5 +0,0 @@ -// test DependentMethodTpeConversionToFunctionError -object Test { - def foo(x: AnyRef): x.type = x - val x: Any => Any = foo -} diff --git a/test/files/run/eta-dependent.check b/test/files/run/eta-dependent.check new file mode 100644 index 00000000000..afc54b65309 --- /dev/null +++ b/test/files/run/eta-dependent.check @@ -0,0 +1,17 @@ + +scala> val a = "obj" +val a: String = obj + +scala> def f(x: Int): a.type = a +def f(x: Int): a.type + +scala> val f1 = f _ +val f1: Int => a.type = $Lambda + +scala> val f2: Int => a.type = f +val f2: Int => a.type = $Lambda + +scala> val f3: Int => Object = f +val f3: Int => Object = $Lambda + +scala> :quit diff --git a/test/files/run/eta-dependent.scala b/test/files/run/eta-dependent.scala new file mode 100644 index 00000000000..2afd6fc8229 --- /dev/null +++ b/test/files/run/eta-dependent.scala @@ -0,0 +1,58 @@ +object NoMoreNeg { + def foo(x: AnyRef): x.type = x + val x: AnyRef => Any = foo +} + +object t12641 { + def f(sb: StringBuilder) = Option("").foreach(sb.append) +} + +object t12641a { + trait A { + def foo(s: String): this.type + def foo(s: Int): this.type + } + trait T { + val a1: A + val o: Option[String] + + def t(a2: A): Unit = { + o.foreach(a1.foo) + o.foreach(a2.foo) + + val f1: String => a2.type = a2.foo _ + val f2: String => A = a2.foo _ + } + } +} + +object t12641b { + trait A { + def foo(s: String): this.type + } + trait T { + val a1: A + val o: Option[String] + + def t(a2: A): Unit = { + o.foreach(a1.foo) + o.foreach(a2.foo) + + val f1: String => a2.type = a2.foo _ + val f2: String => A = a2.foo _ + } + } +} + +import scala.tools.partest.ReplTest + +object Test extends ReplTest { + override protected def normalize(s: String): String = s.replaceAll("(Lambda).*", "$1") + def code = """ +val a = "obj" +def f(x: Int): a.type = a +val f1 = f _ +val f2: Int => a.type = f +val f3: Int => Object = f +""".trim +}