-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Warn on misleading indentation in single-case catch #14738
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 4 commits
2855693
36300dc
d7fb8bf
a670518
a7ffc8e
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 |
---|---|---|
|
@@ -33,7 +33,7 @@ object ShadowingTests: | |
val subdir = dir.resolve(name) | ||
try Files.createDirectory(subdir) | ||
catch case _: java.nio.file.FileAlreadyExistsException => | ||
assert(Files.isDirectory(subdir), s"failed to create shadowed subdirectory $subdir") | ||
assert(Files.isDirectory(subdir), s"failed to create shadowed subdirectory $subdir") | ||
Comment on lines
35
to
+36
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. Wait, I believe my intention there was to swallow the FileAlreadyExistsException, not for the assert to be the body of the catch ... 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. OK, fixed. Goes to show that this really is a dangerous trap. Can we make it an error? I don't see how without undermining fundamental assumptions how the parser works. According to the syntax we need an 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. No wait, it's asserting that the existing thing is a dir, right? If createDir succeeds, it better be a dir. 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. One way to clarify the syntax is to require the expr to begin on the same line as the arrow. So the arrow could move to the following line. 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. In fact the warning occurrences in the backend were also assuming an empty 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. @som-snytt I think you are right for ShadowingTests. The assert really is meant as a handler. @griggt can you confirm? 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'm almost certain that when I wrote it I meant for the catch handler to be empty. But in this case it works either way. 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. In fact, we need more forms of syntax that work either way. If Booleans worked either way, we'd never take the wrong branch. |
||
subdir | ||
|
||
// The directory on the classpath containing artifacts to be shadowed | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import scala.util.chaining.given | ||
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. This seems to be useless/irrelevant.
odersky marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
class C: | ||
def op: Unit = println("op") | ||
def handler: Unit = println("handler") | ||
def test: Unit = | ||
try op | ||
catch case _: NullPointerException => | ||
handler // error |
Uh oh!
There was an error while loading. Please reload this page.