File tree Expand file tree Collapse file tree 4 files changed +16
-4
lines changed
compiler/src/dotty/tools/dotc/typer
tests/neg-custom-args/impl-conv Expand file tree Collapse file tree 4 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -607,15 +607,24 @@ trait Checking {
607607 /** If `sym` is an implicit conversion, check that implicit conversions are enabled.
608608 * @pre sym.is(Implicit)
609609 */
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 = {
613612 checkFeature(
614613 defn.LanguageModuleClass , nme.implicitConversions,
615614 i " Definition of implicit conversion $sym" ,
616615 ctx.owner.topLevelClass,
617616 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+ }
619628 }
620629
621630 /** 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
14191419 def typedValDef (vdef : untpd.ValDef , sym : Symbol )(implicit ctx : Context ): Tree = track(" typedValDef" ) {
14201420 val ValDef (name, tpt, _) = vdef
14211421 completeAnnotations(vdef, sym)
1422+ if (sym is Implicit ) checkImplicitConversionDefOK(sym)
14221423 val tpt1 = checkSimpleKinded(typedType(tpt))
14231424 val rhs1 = vdef.rhs match {
14241425 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
33object A {
44
55 implicit def s2i (x : String ): Int = Integer .parseInt(x) // error: feature
6+ implicit val i2s : ImplicitConverter [Int , String ] = _.toString // error: feature
67
78 implicit class Foo (x : String ) {
89 def foo = x.length
Original file line number Diff line number Diff line change @@ -6,5 +6,6 @@ object B {
66 " " .foo
77
88 val x : Int = " " // error: feature
9+ val y : String = 1 // error: feature
910
1011}
You can’t perform that action at this time.
0 commit comments