File tree 4 files changed +16
-4
lines changed
compiler/src/dotty/tools/dotc/typer
tests/neg-custom-args/impl-conv
4 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -607,15 +607,24 @@ trait Checking {
607
607
/** If `sym` is an implicit conversion, check that implicit conversions are enabled.
608
608
* @pre sym.is(Implicit)
609
609
*/
610
- def checkImplicitConversionDefOK (sym : Symbol )(implicit ctx : Context ): Unit = sym.info.stripPoly match {
611
- case mt @ MethodType (_ :: Nil )
612
- if ! mt.isImplicitMethod && ! sym.is(Synthetic ) => // it's a conversion
610
+ def checkImplicitConversionDefOK (sym : Symbol )(implicit ctx : Context ): Unit = {
611
+ def check (): Unit = {
613
612
checkFeature(
614
613
defn.LanguageModuleClass , nme.implicitConversions,
615
614
i " Definition of implicit conversion $sym" ,
616
615
ctx.owner.topLevelClass,
617
616
sym.pos)
618
- case _ =>
617
+ }
618
+
619
+ sym.info.stripPoly match {
620
+ case mt @ MethodType (_ :: Nil )
621
+ if ! mt.isImplicitMethod && ! sym.is(Synthetic ) => // it's a conversion
622
+ check()
623
+ case AppliedType (tycon, _)
624
+ if tycon.derivesFrom(defn.Predef_ImplicitConverter ) && ! sym.is(Synthetic ) =>
625
+ check()
626
+ case _ =>
627
+ }
619
628
}
620
629
621
630
/** If `sym` is an implicit conversion, check that that implicit conversions are enabled, unless
Original file line number Diff line number Diff line change @@ -1419,6 +1419,7 @@ class Typer extends Namer
1419
1419
def typedValDef (vdef : untpd.ValDef , sym : Symbol )(implicit ctx : Context ): Tree = track(" typedValDef" ) {
1420
1420
val ValDef (name, tpt, _) = vdef
1421
1421
completeAnnotations(vdef, sym)
1422
+ if (sym is Implicit ) checkImplicitConversionDefOK(sym)
1422
1423
val tpt1 = checkSimpleKinded(typedType(tpt))
1423
1424
val rhs1 = vdef.rhs match {
1424
1425
case rhs @ Ident (nme.WILDCARD ) => rhs withType tpt1.tpe
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package implConv
3
3
object A {
4
4
5
5
implicit def s2i (x : String ): Int = Integer .parseInt(x) // error: feature
6
+ implicit val i2s : ImplicitConverter [Int , String ] = _.toString // error: feature
6
7
7
8
implicit class Foo (x : String ) {
8
9
def foo = x.length
Original file line number Diff line number Diff line change @@ -6,5 +6,6 @@ object B {
6
6
" " .foo
7
7
8
8
val x : Int = " " // error: feature
9
+ val y : String = 1 // error: feature
9
10
10
11
}
You can’t perform that action at this time.
0 commit comments