mirror of
https://github.com/dart-lang/sdk
synced 2024-09-19 15:21:31 +00:00
Resolve rethrow.
R=brianwilkerson@google.com, paulberry@google.com Change-Id: Ifb93dc66e80575bb3145d835b3e6e3195e4299be Reviewed-on: https://dart-review.googlesource.com/66661 Reviewed-by: Paul Berry <paulberry@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
parent
726b4c035b
commit
7fc6bf307f
|
@ -1468,12 +1468,6 @@ class CompileTimeErrorCodeTest_Kernel extends CompileTimeErrorCodeTest_Driver {
|
|||
await super.test_referencedBeforeDeclaration_type_localVariable();
|
||||
}
|
||||
|
||||
@override
|
||||
@failingTest
|
||||
test_rethrowOutsideCatch() async {
|
||||
await super.test_rethrowOutsideCatch();
|
||||
}
|
||||
|
||||
@override
|
||||
@failingTest
|
||||
test_returnInGenerativeConstructor() async {
|
||||
|
|
|
@ -4380,6 +4380,19 @@ main() {
|
|||
assertType(tRef, useCFE ? 'dynamic' : null);
|
||||
}
|
||||
|
||||
test_invalid_rethrow() async {
|
||||
addTestFile('''
|
||||
main() {
|
||||
rethrow;
|
||||
}
|
||||
''');
|
||||
await resolveTestFile();
|
||||
expect(result.errors, isNotEmpty);
|
||||
|
||||
var rethrowExpression = findNode.rethrow_('rethrow;');
|
||||
expect(rethrowExpression.staticType, isBottomType);
|
||||
}
|
||||
|
||||
test_isExpression() async {
|
||||
String content = r'''
|
||||
void main() {
|
||||
|
@ -9729,6 +9742,10 @@ class FindNode {
|
|||
return _node(search).getAncestor((n) => n is PrefixedIdentifier);
|
||||
}
|
||||
|
||||
RethrowExpression rethrow_(String search) {
|
||||
return _node(search).getAncestor((n) => n is RethrowExpression);
|
||||
}
|
||||
|
||||
SimpleIdentifier simple(String search) {
|
||||
return _node(search);
|
||||
}
|
||||
|
|
|
@ -5990,6 +5990,15 @@ const MessageCode messageRequiredParameterWithDefault = const MessageCode(
|
|||
tip:
|
||||
r"""Try removing the default value or making the parameter optional.""");
|
||||
|
||||
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
|
||||
const Code<Null> codeRethrowNotCatch = messageRethrowNotCatch;
|
||||
|
||||
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
|
||||
const MessageCode messageRethrowNotCatch = const MessageCode("RethrowNotCatch",
|
||||
analyzerCode: "RETHROW_OUTSIDE_CATCH",
|
||||
dart2jsCode: "*fatal*",
|
||||
message: r"""'rethrow' can only be used in catch clauses.""");
|
||||
|
||||
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
|
||||
const Code<Null> codeReturnFromVoidFunction = messageReturnFromVoidFunction;
|
||||
|
||||
|
|
|
@ -3453,13 +3453,14 @@ abstract class BodyBuilder extends ScopeListener<JumpTarget>
|
|||
@override
|
||||
void endRethrowStatement(Token rethrowToken, Token endToken) {
|
||||
debugEvent("RethrowStatement");
|
||||
if (inCatchBlock) {
|
||||
push(forest.rethrowStatement(rethrowToken, endToken));
|
||||
} else {
|
||||
push(deprecated_buildCompileTimeErrorStatement(
|
||||
"'rethrow' can only be used in catch clauses.",
|
||||
rethrowToken.charOffset));
|
||||
}
|
||||
var error = inCatchBlock
|
||||
? null
|
||||
: buildCompileTimeError(fasta.messageRethrowNotCatch,
|
||||
offsetForToken(rethrowToken), lengthForToken(rethrowToken));
|
||||
push(new ExpressionStatementJudgment(
|
||||
new RethrowJudgment(rethrowToken, error)
|
||||
..fileOffset = offsetForToken(rethrowToken),
|
||||
endToken));
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -488,7 +488,7 @@ class Fangorn extends Forest {
|
|||
@override
|
||||
Statement rethrowStatement(Token rethrowKeyword, Token semicolon) {
|
||||
return new ExpressionStatementJudgment(
|
||||
new RethrowJudgment(rethrowKeyword)
|
||||
new RethrowJudgment(rethrowKeyword, null)
|
||||
..fileOffset = offsetForToken(rethrowKeyword),
|
||||
semicolon);
|
||||
}
|
||||
|
|
|
@ -108,6 +108,7 @@ export 'kernel_shadow_ast.dart'
|
|||
PropertyAssignmentJudgment,
|
||||
PropertyGetJudgment,
|
||||
RedirectingInitializerJudgment,
|
||||
RethrowJudgment,
|
||||
ReturnJudgment,
|
||||
StaticAssignmentJudgment,
|
||||
StaticGetJudgment,
|
||||
|
|
|
@ -2500,10 +2500,11 @@ class RedirectingInitializerJudgment extends RedirectingInitializer
|
|||
/// Shadow object for [Rethrow].
|
||||
class RethrowJudgment extends Rethrow implements ExpressionJudgment {
|
||||
final Token rethrowKeyword;
|
||||
final kernel.Expression desugaredError;
|
||||
|
||||
DartType inferredType;
|
||||
|
||||
RethrowJudgment(this.rethrowKeyword);
|
||||
RethrowJudgment(this.rethrowKeyword, this.desugaredError);
|
||||
|
||||
@override
|
||||
Expression infer<Expression, Statement, Initializer, Type>(
|
||||
|
@ -2512,6 +2513,10 @@ class RethrowJudgment extends Rethrow implements ExpressionJudgment {
|
|||
DartType typeContext) {
|
||||
inferredType = const BottomType();
|
||||
inferrer.listener.rethrow_(this, fileOffset, rethrowKeyword, inferredType);
|
||||
if (desugaredError != null) {
|
||||
parent.replaceChild(this, desugaredError);
|
||||
parent = null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -292,6 +292,7 @@ RedirectingConstructorWithBody/script1: Fail
|
|||
RedirectionInNonFactory/script1: Fail
|
||||
RedirectionTargetNotFound/analyzerCode: Fail
|
||||
RedirectionTargetNotFound/example: Fail
|
||||
RethrowNotCatch/example: Fail
|
||||
ReturnTypeFunctionExpression/analyzerCode: Fail
|
||||
ReturnTypeFunctionExpression/example: Fail
|
||||
SdkRootNotFound/analyzerCode: Fail
|
||||
|
|
|
@ -2737,3 +2737,8 @@ ReturnFromVoidFunction:
|
|||
analyzerCode: RETURN_OF_INVALID_TYPE
|
||||
dart2jsCode: "*fatal*"
|
||||
declaration: "void foo() { return 1; }"
|
||||
|
||||
RethrowNotCatch:
|
||||
template: "'rethrow' can only be used in catch clauses."
|
||||
analyzerCode: RETHROW_OUTSIDE_CATCH
|
||||
dart2jsCode: "*fatal*"
|
||||
|
|
Loading…
Reference in a new issue