1
1
mirror of https://github.com/github/semantic.git synced 2025-01-05 14:11:33 +03:00

Merge pull request #238 from github/fix-try-catch-error

Assignment error in Java try/catch blocks (#235)
This commit is contained in:
Rob Rix 2019-09-06 14:24:52 -04:00 committed by GitHub
commit a9365c667c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 3 deletions

View File

@ -452,16 +452,19 @@ throw :: Assignment Term
throw = makeTerm <$> symbol ThrowStatement <*> children (Statement.Throw <$> term expression)
try :: Assignment Term
try = symbol TryStatement *> children tryWithResources <|> makeTerm <$> symbol TryStatement <*> children (Statement.Try <$> term expression <*> (append <$> optional catches <*> optional finally))
try = symbol TryStatement *> children tryWithResources <|> standardTry
standardTry :: Assignment Term
standardTry = makeTerm <$> symbol TryStatement <*> children (Statement.Try <$> term expression <*> (append <$> optional catches <*> optional finally))
catches :: Assignment [Term]
catches = symbol Catches *> children (manyTerm catch)
where
catch = makeTerm <$> symbol CatchClause <*> children (Statement.Catch <$> catchFormalParameter <*> term expression)
catch = makeTerm <$> symbol CatchClause <*> children (Statement.Catch <$> catchFormalParameter <*> block)
catchFormalParameter = makeTerm <$> symbol CatchFormalParameter <*> children (flip Type.Annotation <$> catchType <* symbol VariableDeclaratorId <*> children identifier)
catchType :: Assignment Term
catchType = makeTerm <$> symbol CatchType <*> (Java.Syntax.CatchType <$> many type')
catchType = makeTerm <$> symbol CatchType <*> children (Java.Syntax.CatchType <$> many type')
finally :: Assignment Term
finally = makeTerm <$> symbol Finally <*> children (Statement.Finally <$> term expression)

9
test/fixtures/java/corpus/try.java vendored Normal file
View File

@ -0,0 +1,9 @@
public class Bar {
public void foo() {
try {
System.out.println(1/0);
} catch (Exception e) {
e.printStackTrace(System.out);
}
}
}

View File

@ -0,0 +1,9 @@
public class Bar {
public void foo() {
try (BufferedReader br = new BufferedReader()) {
System.out.println(1/0);
} catch (Exception e) {
e.printStackTrace(System.out);
}
}
}