-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Change Ambiguous Import error in Typer to case class #2362
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1223,4 +1223,39 @@ object messages { | |
|Attempting to define a field in a method signature after a varargs field is an error. | ||
|""".stripMargin | ||
} | ||
|
||
case class AmbiguousImport(name: Names.Name, newPrec: Int, prevPrec: Int, prevCtx: Context)(implicit ctx: Context) | ||
extends Message(AmbiguousImportID) { | ||
|
||
import typer.Typer.BindingPrec._ | ||
|
||
/** A string which explains how something was bound; Depending on `prec` this is either | ||
* imported by <tree> | ||
* or defined in <symbol> | ||
*/ | ||
private def bindingString(prec: Int, whereFound: Context, qualifier: String = "") = | ||
if (isImportPrec(prec)) { | ||
ex"""imported$qualifier by ${hl"${whereFound.importInfo}"}""" | ||
} else | ||
ex"""defined$qualifier in ${hl"${whereFound.owner.toString}"}""" | ||
|
||
|
||
val msg = | ||
s"""|reference to `${hl"$name"}` is ambiguous | ||
|it is both ${bindingString(newPrec, ctx)} | ||
|and ${bindingString(prevPrec, prevCtx, " subsequently")}""".stripMargin | ||
|
||
val kind = "Reference" | ||
|
||
val explanation = | ||
hl"""|The compiler can't decide which of the possible choices you | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need better integration of formatters. It seems non-sensical that we either get explanations of duplicated values (in ex) or syntax highlighting (in hl) but not both. That's just a side remark, intended for a future PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, the current formatters don't compose well. @felixmulder and I discussed the need automated line wrapping as well. |
||
|are referencing with $name. | ||
|Note: | ||
|- Definitions take precedence over imports | ||
|- Named imports take precedence over wildcard imports | ||
|- You may replace a name when imported using | ||
| ${"import"} scala.{ $name => ${name.show + "Tick"} } | ||
|""".stripMargin | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use
i"""
instead ofs"""
and drop the .stripMargin here.