Skip to content

Fix #1784: allow to omit types for local implicit vals #1785

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Dec 15, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,13 @@ object ErrorReporting {
errorMsg(msg, cx.outer)
}
} else msg
errorMsg(ex.show, ctx)

if (cycleSym.is(Implicit, butNot = Method) && cycleSym.owner.isTerm)
em"""cyclic reference involving implicit $cycleSym
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@felixmulder Line 2 and 3 of this message might be moved to an explanation. But we can also leave it like this, I think.

|This happens when the right hand-side of $cycleSym's definition involves an implicit search.
|To avoid the error, give $cycleSym an explicit type."""
else
errorMsg(ex.show, ctx)
}

def wrongNumberOfArgs(fntpe: Type, kind: String, expectedArgs: List[TypeParamInfo], actual: List[untpd.Tree], pos: Position)(implicit ctx: Context) =
Expand Down
1 change: 0 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,6 @@ class Namer { typer: Typer =>
def missingType(modifier: String) = {
ctx.error(s"${modifier}type of implicit definition needs to be given explicitly", mdef.pos)
sym.resetFlag(Implicit)

}
if (sym is Implicit)
mdef match {
Expand Down
7 changes: 7 additions & 0 deletions tests/neg/implicitDefs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,11 @@ object implicitDefs {
implicit val x = 2 // error: type of implicit definition needs to be given explicitly
implicit def y(x: Int) = 3 // error: result type of implicit definition needs to be given explicitly
implicit def z(a: x.type): String = "" // error: implicit conversion may not have a parameter of singleton type

def foo(implicit x: String) = 1

def bar() = {
implicit val x = foo
x
}
}