Resolve required arguments after named.

Change-Id: I2947be1fc20b1455e7865c34e35349977d61f70b
Reviewed-on: https://dart-review.googlesource.com/71382
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
Konstantin Shcheglov 2018-08-23 22:04:12 +00:00 committed by commit-bot@chromium.org
parent ff3908d6df
commit b255f0fab6
6 changed files with 36 additions and 25 deletions

View file

@ -1061,14 +1061,4 @@ main() { f("16", radix: ^);}''');
class ArgListContributorTest_UseCFE extends ArgListContributorTest {
@override
bool get useCFE => true;
@failingTest
@override
test_ArgumentList_local_constructor_named_param_4() =>
super.test_ArgumentList_local_constructor_named_param_4();
@failingTest
@override
test_ArgumentList_local_constructor_named_param_5() =>
super.test_ArgumentList_local_constructor_named_param_5();
}

View file

@ -4641,6 +4641,21 @@ main() {
assertIdentifierTopGetRef(arg2.expression, 'c');
}
test_invalid_invocation_arguments_requiredAfterNamed() async {
addTestFile(r'''
var a = 0;
var b = 0;
main() {
f(p: a, b);
}
void f({p}) {}
''');
await resolveTestFile();
expect(result.errors, isNotEmpty);
assertTopGetRef('a, ', 'a');
assertTopGetRef('b);', 'b');
}
test_invalid_invocation_arguments_static_method() async {
addTestFile(r'''
class C {

View file

@ -1098,12 +1098,14 @@ abstract class BodyBuilder extends ScopeListener<JumpTarget>
Expression argument = toValue(node);
arguments[i] = argument;
if (i > firstNamedArgumentIndex) {
arguments[i] = new NamedExpression(
"#$i",
arguments[i] = new NamedExpressionJudgment(
tokensSaver?.namedExpressionTokens(null, null),
'#$i',
buildCompileTimeErrorExpression(
fasta.messageExpectedNamedArgument,
forest.readOffset(argument)))
..fileOffset = beginToken.charOffset;
forest.readOffset(argument)),
originalValue: argument)
..fileOffset = offsetForToken(beginToken);
}
}
}

View file

@ -3716,10 +3716,17 @@ class CheckLibraryIsLoadedJudgment extends CheckLibraryIsLoaded
/// Concrete shadow object representing a named expression.
class NamedExpressionJudgment extends NamedExpression {
NamedExpressionTokens tokens;
final NamedExpressionTokens tokens;
NamedExpressionJudgment(this.tokens, String nameLexeme, Expression value)
: super(nameLexeme, value);
/// The original value that is wrapped by this synthetic named argument.
/// Its type will be inferred.
final Expression originalValue;
NamedExpressionJudgment(this.tokens, String nameLexeme, Expression value,
{this.originalValue})
: super(nameLexeme, value) {
originalValue?.parent = this;
}
ExpressionJudgment get judgment => value;
}

View file

@ -1956,13 +1956,14 @@ abstract class TypeInferrerImpl extends TypeInferrer {
return new InterfaceType(class_, <DartType>[type ?? const DynamicType()]);
}
void _forEachArgument(
Arguments arguments, void callback(String name, Expression expression)) {
void _forEachArgument(ArgumentsJudgment arguments,
void callback(String name, Expression expression)) {
for (var expression in arguments.positional) {
callback(null, expression);
}
for (var namedExpression in arguments.named) {
callback(namedExpression.name, namedExpression.value);
for (var namedExpression in arguments.namedJudgments) {
callback(namedExpression.name,
namedExpression.originalValue ?? namedExpression.value);
}
}

View file

@ -27,10 +27,6 @@ constructor_with_type_parameters_test/03: MissingCompileTimeError
[ $compiler == dart2analyzer && $fasta ]
arg_param_trailing_comma_test/100: Crash # Issue #34043 - Error recovery in outline (extraneous comma before formal parameter)
arg_param_trailing_comma_test/138: Crash # Error recovery in method body (synthetic argument)
arg_param_trailing_comma_test/147: Crash # Error recovery in method body (synthetic argument)
arg_param_trailing_comma_test/156: Crash # Error recovery in method body (synthetic argument)
arg_param_trailing_comma_test/165: Crash # Error recovery in method body (synthetic argument)
arg_param_trailing_comma_test/24: Crash # Issue #34043 - Error recovery in outline (extraneous comma before formal parameter)
arg_param_trailing_comma_test/25: Crash # Issue #34043 - Error recovery in outline (extraneous comma before formal parameter)
arg_param_trailing_comma_test/26: Crash # Issue #34043 - Error recovery in outline (extraneous comma before formal parameter)