Skip to content

SI-9834 Improve error on failed op=#5454

Merged
adriaanm merged 2 commits intoscala:2.11.xfrom
som-snytt:issue/9834-2.11
Dec 15, 2016
Merged

SI-9834 Improve error on failed op=#5454
adriaanm merged 2 commits intoscala:2.11.xfrom
som-snytt:issue/9834-2.11

Conversation

@som-snytt
Copy link
Contributor

If rewriting x += y fails to typecheck, emit error messages
for both the original tree and the assignment.

If rewrite is not attempted because x is a val, then say so.

Supersedes #5254 from last June. I must've forgotten it was against 2.11. What fashions did we wear and what music did we listen to back then? Who was president?

@scala-jenkins scala-jenkins added this to the 2.11.9 milestone Oct 12, 2016
@adriaanm adriaanm self-assigned this Oct 18, 2016
Copy link
Contributor

@adriaanm adriaanm left a comment

Choose a reason for hiding this comment

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

Looks good overall, but I have a few questions after a first pass.

if (Statistics.canEnable) Statistics.stopTimer(failedApplyNanos, appStart)
reportError
val t = reportError
val Apply(Select(qual2, _), args2) = t
Copy link
Contributor

Choose a reason for hiding this comment

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

val t@Apply(Select(qual2, _), args2) = reportError?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Check! People think newlines grow on trees. Wait was that a compiler joke? Next time someone asks for a feature, People think syntax grows on trees!

case SilentResultValue(t) => t
case err: SilentTypeError =>
val t = reportError
context.reporter.echo("Expression does not convert to assignment because:")
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the reasoning behind echoing? I'd expect to see context.issue/context.warning?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because there's no context.reporter.sendTextAlert? I don't remember, so you're probably right as rain.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I remember now, we're just appending to the reported error; we don't want to bump an error or warning count.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reportError function should take the optional text to append.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, I don't know what 'start a review' and 'review changes' buttons do yet.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this may be missed by tools, like Ensime/Eclipse and maybe even Sbt. It might play better if the additional text was part of the original error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought about it briefly last night and agree, but not sure about code yet. I haven't looked at dotty "explain" messages yet, and whether they include an "append advice" feature. I like the idea of decoupled, "something happened, and this additional text may help."

@som-snytt
Copy link
Contributor Author

More retro history is that the crasher fix on 2.12 is #5179

@som-snytt
Copy link
Contributor Author

Before issuing errors, update the error(s) at the tree.pos with the additional text. It would be nicer to err.copy(errMsg = "more") to preserve the actual TypeError in case a reporter cares.

@som-snytt
Copy link
Contributor Author

@SethTisue "Hello, Seth, can you tell me how I broke the build?" (If I could talk to Seth's Build Tool like Siri.)

@adriaanm
Copy link
Contributor

adriaanm commented Nov 1, 2016

scala/scala-dev#251 is looking less and less spurious.

@som-snytt
Copy link
Contributor Author

“Spuriouser and spuriouser!” Cried Alice (she was so much surprised, that for the moment she quite forgot how to speak good English).

@som-snytt
Copy link
Contributor Author

How about showing the expansion as well:

scala> val arr1 = new Array[Byte](10)
arr1: Array[Byte] = Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0)

scala> val arr2 = new Array[Byte](10)
arr2: Array[Byte] = Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0)

scala> arr1(4) ^= arr2(5)
<console>:14: error: value ^= is not a member of Byte
  Expression does not convert to assignment because:
    type mismatch;
     found   : Int
     required: Byte
    expansion: arr1.update(4, arr1.apply(4).^(arr2(5)))
       arr1(4) ^= arr2(5)
               ^

scala> val j = collection.mutable.Set("a")
j: scala.collection.mutable.Set[String] = Set(a)

scala> j("a") += "b"
<console>:13: error: value += is not a member of Boolean
  Expression does not convert to assignment because:
    type mismatch;
     found   : String
     required: Boolean
    expansion: j.update("a", j.apply("a").$plus("b"))
       j("a") += "b"
              ^

I see the caret operator is not shown as $up.

If rewriting `x += y` fails to typecheck, emit error messages
for both the original tree and the assignment.

If rewrite is not attempted because `x` is a val, then say so.

The error message at `tree.pos` is updated with the additional advice.

SI-8763 Crash in update conversion

When there are already errors, don't attempt mechanical rewrites.
@som-snytt
Copy link
Contributor Author

/rebuild

@lrytz
Copy link
Member

lrytz commented Dec 14, 2016

Looks very nice. Could we even include the receiver expression? Expression does not convert to assignment because x is not assignable.

@retronym
Copy link
Member

Could we even include the receiver expression

This can lead to poor messages in cases when the expression is long, or contained desugarings. Usually we just identify it with the error position and only refer to the expressions type in the message.

@som-snytt
Copy link
Contributor Author

That was my original reason, although the word receiver could be poorly received. But maybe use a simple ident when you've got one.

I also forgot my comment that the expansion string shows $plus but not $up. What's $up with that? Or more colloquially, Wass^?

The message will be perfect in dotty...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants