-
Notifications
You must be signed in to change notification settings - Fork 323
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
Fix rendering of redefined Conversion error #8245
Conversation
ideally we should fix the root cause
bfe2cea
to
9a81242
Compare
engine/runtime-parser/src/main/java/org/enso/compiler/core/TreeToIr.java
Show resolved
Hide resolved
s"Method overloads are not supported: ${targetType.map(_.name + ".").getOrElse("")}from " + | ||
s"Ambiguous conversion: ${targetType.map(_.name + ".").getOrElse("")}from " + |
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.
I think that this error message may be clearer - conversions work a bit differently than method overloads - they do overload the from
method, just with different types of that
.
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.
What if I accidentaly do something like this:
method x y = x + y
method x = x
Would the error message say "Ambiguous conversion" in that case as well? Isn't that misleading? What about trying to distinguish between those two cases - "Ambiguous conversion" VS "Method overload"?
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.
We do distinguish these cases already.
The error message I have edited was only relevant for conversions, method overloads have a separate error class - I assume the error message for conversions was copy-pasted from overloads and that's why it used to say the same thing.
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 see here a test verifying that the behaviour is exactly as you'd expect it to be.
Lines 33 to 42 in b9328bd
the[InterpreterException] thrownBy eval(code) should have message | |
"Compilation aborted due to errors." | |
val diagnostics = consumeOut | |
diagnostics | |
.filterNot(isDiagnosticLine) | |
.toSet shouldEqual Set( | |
"Test:4:1: error: Method overloads are not supported: Nothing.foo is defined multiple times in this module." | |
) | |
} |
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.
Well, the above test was for member methods - so just to be comprehensive I added a test case like the one you mentioned:
2a37e54
.../runtime-with-instruments/src/test/scala/org/enso/interpreter/test/instrument/ReplTest.scala
Show resolved
Hide resolved
s"(Redefined (Conversion ${targetType.map(_.showCode() + ".").getOrElse("")}from $sourceType))" | ||
s"(Redefined (Conversion ${targetType.map(_.showCode() + ".").getOrElse("")}from ${sourceType.showCode()}))" |
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.
Small irrelevant fix - before printing the redefined conversion as code was leaking a lot of information by using toString
instead of showCode
for the sourceType
. With that it is more compact and closer to what I think showCode
is supposed to be.
engine/runtime-with-polyglot/src/test/java/org/enso/interpreter/test/ConversionMethodTests.java
Outdated
Show resolved
Hide resolved
@@ -32,6 +32,14 @@ protected static Context createDefaultContext() { | |||
return context; | |||
} | |||
|
|||
protected static Context createNonStrictContext(OutputStream out) { |
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.
Is there only single usage of this method? Consider using createDefaultContext
and apply the STRICT_ERRORS
option to it.
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.
Can I apply options to a Context after it was constructed?
// But we should still get the diagnostic! | ||
MatcherAssert.assertThat(getStdOut(), Matchers.containsString("Unnamed:7:1: error: Ambiguous conversion: Foo.from Bar is defined multiple times in this module.")); |
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.
I had to remove this check, because currently apparently the diagnostics are not reported at all in the non-strict mode.
e.g.
enso/engine/runtime-compiler/src/main/scala/org/enso/compiler/Compiler.scala
Lines 899 to 918 in 24c0804
def runErrorHandling( | |
modules: List[Module] | |
): Unit = { | |
if (config.isStrictErrors) { | |
val diagnostics = modules.flatMap { module => | |
val errors = gatherDiagnostics(module) | |
List((module, errors)) | |
} | |
if (reportDiagnostics(diagnostics)) { | |
val count = | |
diagnostics.map(_._2.collect { case e: Error => e }.length).sum | |
val warnCount = | |
diagnostics.map(_._2.collect { case e: Warning => e }.length).sum | |
context.getErr.println( | |
s"Aborting due to ${count} errors and ${warnCount} warnings." | |
) | |
throw new CompilationAbortedException | |
} | |
} | |
} |
cc: @JaroslavTulach @hubertp is this preferred for some reason? Do we not report the diagnostics, because non-strict mode is essentially interactive mode and these error messages are supposed to reach the IDE through 'other means' (i.e. errors baked in the IR)? Or is this just an oversight?
My intuition is that actually logging these kinds of diagnostics may make it easier to debug issues when IDE fails to execute something, so I'd be happy to enable them, but I first need to know if there is some reason for not-enabling them that I'm not aware of.
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.
minors. Otherwise LGTM.
s"Method overloads are not supported: ${targetType.map(_.name + ".").getOrElse("")}from " + | ||
s"Ambiguous conversion: ${targetType.map(_.name + ".").getOrElse("")}from " + |
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.
What if I accidentaly do something like this:
method x y = x + y
method x = x
Would the error message say "Ambiguous conversion" in that case as well? Isn't that misleading? What about trying to distinguish between those two cases - "Ambiguous conversion" VS "Method overload"?
Pull Request Description
from
conversions are encountered #7853Important Notes
Checklist
Please ensure that the following checklist has been satisfied before submitting the PR:
Scala,
Java,
and
Rust
style guides. In case you are using a language not listed above, follow the Rust style guide.
./run ide build
.