Skip to content

Commit 1c03d45

Browse files
committed
Fix #1784: allow to omit types for local implicit vals
1 parent 740ccf8 commit 1c03d45

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

compiler/src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -998,11 +998,17 @@ class Namer { typer: Typer =>
998998
lhsType // keep constant types that fill in for a non-constant (to be revised when inline has landed).
999999
else inherited
10001000
else {
1001-
if (sym is Implicit) {
1002-
val resStr = if (mdef.isInstanceOf[DefDef]) "result " else ""
1003-
ctx.error(s"${resStr}type of implicit definition needs to be given explicitly", mdef.pos)
1001+
def missingType(modifier: String) = {
1002+
ctx.error(s"${modifier}type of implicit definition needs to be given explicitly", mdef.pos)
10041003
sym.resetFlag(Implicit)
1004+
10051005
}
1006+
if (sym is Implicit)
1007+
mdef match {
1008+
case _: DefDef => missingType("result")
1009+
case _: ValDef if sym.owner.isType => missingType("")
1010+
case _ =>
1011+
}
10061012
lhsType orElse WildcardType
10071013
}
10081014
}

tests/pos/implicits.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,9 @@ object Test {
66

77
val x: X = Byte.MinValue
88

9+
def foo() = {
10+
implicit val x = "abc"
11+
implicitly[String]
12+
}
13+
914
}

0 commit comments

Comments
 (0)