question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Misleading error message when forgetting `using` in explicitly given context argument

See original GitHub issue

Compiler version

Welcome to Scala 3.1.3 (17.0.3, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.

Minimized code and output

scala> def f(using i: Int) = i + 1
def f(using i: Int): Int

scala> f(41)
-- Error: -----------------------------------------------
1 |f(41)
  | ^
  | no given instance of type Int was found for parameter i of method f
1 error found

Expectation

It is true that there is no given instance above, but the call is still erroneous and the error message does not help if the user just forgot an explicit using before the explicit argument. Even if a given is missing, something similar to this error should (also) be shown :

scala> f(41)
-- [E050] Type Error: ---------------------------------------
  |^
  |method f does not take more parameters
  |
  | longer explanation available when compiling with `-explain`
1 error found

but it would be more helpful if a hint that “you may have forgotten using” also is given.

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
som-snyttcommented, Jul 7, 2022

I’ll take a quick look; it’s probably an easy tweak; I just added benign using to Scala 2 and was contemplating misusages. Lukas said what about f(using using).

0reactions
bjornregnellcommented, Jul 8, 2022

If we do want to suggest a missing using, we should make sure that the next argument list would be legal, in what concerns both the number of parameters and their types.

I do think that if the user has forgotten using but meant to call it with an explicit argument then the current error message could be more helpful. If it is possible to make the hint in only those cases were it is a valid rewrite to add using then I think it is worthwhile to give the hint that it may be missing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Master List of Logical Fallacies
Master List of Logical Fallacies. Fallacies are fake or deceptive arguments, "junk cognition," that is, arguments that seem irrefutable but prove nothing. ...
Read more >
Context Managers and Python's with Statement
Note: A common mistake when you're using context managers is forgetting to call the object passed to the with statement. The exception message...
Read more >
A Definitive Guide to Handling Errors in JavaScript - Kinsta
It usually occurs when passing a value as an argument to a function, and the given value doesn't lie in the range of...
Read more >
R: '...' used in an incorrect context - Stack Overflow
I have looked at about 40 instances of this error on stackoverflow, ... other instances displayed, and I do not know what is...
Read more >
Explanation of the error messages for the W3C Markup Validator
forgetting to quote an attribute value (where characters such as "%" and "/" are common, but cannot appear without surrounding quotes), or; using...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found