Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 1a039e5

Browse files
author
Dart CI
committed
Version 2.11.0-185.0.dev
Merge commit '090166c79d65c8b9c58a9651f7056c1b380d0442' into 'dev'
2 parents 9f810fa + 090166c commit 1a039e5

File tree

3 files changed

+58
-2
lines changed

3 files changed

+58
-2
lines changed

pkg/analyzer/lib/src/generated/resolver.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,11 +630,21 @@ class ResolverVisitor extends ScopedVisitor {
630630
);
631631
} else if (node is SimpleIdentifier) {
632632
var resolver = PropertyElementResolver(this);
633-
return resolver.resolveSimpleIdentifier(
633+
var result = resolver.resolveSimpleIdentifier(
634634
node: node,
635635
hasRead: hasRead,
636636
hasWrite: true,
637637
);
638+
639+
if (hasRead && result.readElementRequested == null) {
640+
errorReporter.reportErrorForNode(
641+
CompileTimeErrorCode.UNDEFINED_IDENTIFIER,
642+
node,
643+
[node.name],
644+
);
645+
}
646+
647+
return result;
638648
} else {
639649
node.accept(this);
640650
return PropertyElementResolverResult();

pkg/analyzer/test/src/diagnostics/undefined_identifier_test.dart

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,28 @@ class A {
2828
]);
2929
}
3030

31+
test_compoundAssignment_noGetter_hasSetter() async {
32+
await assertErrorsInCode('''
33+
set foo(int _) {}
34+
35+
void f() {
36+
foo += 0;
37+
}
38+
''', [
39+
error(CompileTimeErrorCode.UNDEFINED_IDENTIFIER, 32, 3),
40+
]);
41+
}
42+
43+
test_compoundAssignment_noGetter_noSetter() async {
44+
await assertErrorsInCode('''
45+
void f() {
46+
foo += 0;
47+
}
48+
''', [
49+
error(CompileTimeErrorCode.UNDEFINED_IDENTIFIER, 13, 3),
50+
]);
51+
}
52+
3153
test_for() async {
3254
await assertErrorsInCode('''
3355
f(var l) {
@@ -126,6 +148,30 @@ f() { C.m(); }
126148
]);
127149
}
128150

151+
test_postfixExpression_increment_noGetter_hasSetter() async {
152+
await assertErrorsInCode('''
153+
set foo(int _) {}
154+
155+
void f() {
156+
foo++;
157+
}
158+
''', [
159+
error(CompileTimeErrorCode.UNDEFINED_IDENTIFIER, 32, 3),
160+
]);
161+
}
162+
163+
test_prefixExpression_increment_noGetter_hasSetter() async {
164+
await assertErrorsInCode('''
165+
set foo(int _) {}
166+
167+
void f() {
168+
++foo;
169+
}
170+
''', [
171+
error(CompileTimeErrorCode.UNDEFINED_IDENTIFIER, 34, 3),
172+
]);
173+
}
174+
129175
test_private_getter() async {
130176
newFile('$testPackageLibPath/lib.dart', content: '''
131177
library lib;

tools/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ CHANNEL dev
2727
MAJOR 2
2828
MINOR 11
2929
PATCH 0
30-
PRERELEASE 184
30+
PRERELEASE 185
3131
PRERELEASE_PATCH 0

0 commit comments

Comments
 (0)