Skip to content

Commit fa0b38b

Browse files
danrubelcommit-bot@chromium.org
authored andcommitted
Fix some constructor initializer code completion situations
Change-Id: Ibbe079d79889846e34ab98ccdc11ef6fcc788654 Reviewed-on: https://dart-review.googlesource.com/75600 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Dan Rubel <[email protected]>
1 parent 2455141 commit fa0b38b

File tree

3 files changed

+33
-11
lines changed

3 files changed

+33
-11
lines changed

pkg/analysis_server/test/domain_completion_test.dart

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@ class A {
180180
expect(suggestions, hasLength(2));
181181
}
182182

183-
@FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/33992')
184183
test_constructor() async {
185184
addTestFile('class A {bool foo; A() : ^;}');
186185
await getSuggestions();
@@ -200,7 +199,6 @@ class A {
200199
relevance: DART_RELEVANCE_LOCAL_FIELD);
201200
}
202201

203-
@FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/33992')
204202
test_constructor3() async {
205203
addTestFile('class A {bool foo; A() : a=7,^;}');
206204
await getSuggestions();
@@ -230,7 +228,6 @@ class A {
230228
relevance: DART_RELEVANCE_LOCAL_FIELD);
231229
}
232230

233-
@FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/33992')
234231
test_constructor6() async {
235232
addTestFile('class A {bool foo; A() : a=7,^ void bar() {}}');
236233
await getSuggestions();
@@ -538,11 +535,11 @@ class A {
538535
relevance: DART_RELEVANCE_LOCAL_FUNCTION);
539536
}
540537

541-
@FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/33992')
542538
test_inherited() {
543-
newFile('/libA.dart', content: 'class A {m() {}}');
544539
addTestFile('''
545-
import ${convertPathForImport('/libA.dart')};
540+
class A {
541+
m() {}
542+
}
546543
class B extends A {
547544
x() {^}
548545
}

pkg/analyzer/test/src/fasta/recovery/partial_code/constructor_test.dart

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,43 @@ class ConstructorTest extends PartialCodeTest {
2020
ParserErrorCode.MISSING_INITIALIZER,
2121
ParserErrorCode.MISSING_FUNCTION_BODY
2222
],
23-
'C() {}',
23+
'C() : _s_ = _s_ {}',
24+
adjustValidUnitBeforeComparison: setSeparator,
25+
failing: ['methodNonVoid', 'getter', 'setter'],
26+
),
27+
new TestDescriptor(
28+
'colon_field',
29+
'C() : f',
30+
[
31+
ParserErrorCode.MISSING_ASSIGNMENT_IN_INITIALIZER,
32+
ParserErrorCode.MISSING_FUNCTION_BODY
33+
],
34+
'C() : _s_ = f {}',
35+
adjustValidUnitBeforeComparison: setSeparator,
36+
),
37+
new TestDescriptor(
38+
'colon_field_comma',
39+
'C() : f = 0,',
40+
[
41+
ParserErrorCode.MISSING_INITIALIZER,
42+
ParserErrorCode.MISSING_FUNCTION_BODY
43+
],
44+
'C() : f = 0, _s_ = _s_ {}',
2445
adjustValidUnitBeforeComparison: setSeparator,
2546
failing: ['methodNonVoid', 'getter', 'setter'],
2647
),
2748
new TestDescriptor(
2849
'colon_block',
2950
'C() : {}',
3051
[ParserErrorCode.MISSING_INITIALIZER],
31-
'C() {}',
52+
'C() : _s_ = _s_ {}',
3253
adjustValidUnitBeforeComparison: setSeparator,
3354
),
3455
new TestDescriptor(
3556
'colon_semicolon',
3657
'C() : ;',
3758
[ParserErrorCode.MISSING_INITIALIZER],
38-
'C();',
59+
'C() : _s_ = _s_ ;',
3960
adjustValidUnitBeforeComparison: setSeparator,
4061
),
4162
new TestDescriptor(

pkg/front_end/lib/src/fasta/parser/parser.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2435,9 +2435,13 @@ class Parser {
24352435
}
24362436
// Fall through to recovery
24372437
} else {
2438-
// Recovery
2439-
insertSyntheticIdentifier(token, IdentifierContext.fieldInitializer,
2438+
// Recovery: Insert a synthetic assignment.
2439+
token = insertSyntheticIdentifier(
2440+
token, IdentifierContext.fieldInitializer,
24402441
message: fasta.messageExpectedAnInitializer, messageOnToken: token);
2442+
token = rewriter.insertToken(
2443+
token, new SyntheticToken(TokenType.EQ, token.offset));
2444+
token = rewriter.insertSyntheticIdentifier(token);
24412445
return parseInitializerExpressionRest(beforeExpression);
24422446
}
24432447
// Recovery

0 commit comments

Comments
 (0)