dart-sdk/tests/language/getter/no_setter_test.dart
Paul Berry 189aeead47 Fix reporting of INSTANCE_ACCESS_TO_STATIC_MEMBER from within an extension.
Previously, if a piece of code inside an extension tried erroneously
to refer to a static class member using instance access, the error
CompileTimeError.UNQUALIFIED_ACCESS_TO_STATIC_MEMBER_OF_EXTENDED_TYPE
would be reported.  This change corrects the error to
CompileTimeError.INSTANCE_ACCESS_TO_STATIC_MEMBER.

In addition, the responsibility to report the error
CompileTimeError.INSTANCE_ACCESS_TO_STATIC_MEMBER is shifted fully to
the resolver (previously, it was split between the resolver and the
error verifier).

Change-Id: Idcd1a3b8a1e226fed692900838c3d2d3c0585d4f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/217020
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2021-10-17 06:22:30 +00:00

51 lines
1.4 KiB
Dart

// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Verifies behavior with a static getter, but no field and no setter.
import "package:expect/expect.dart";
class Example {
static int _var = 1;
static int get nextVar => _var++;
Example() {
nextVar = 1;
// ^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.ASSIGNMENT_TO_FINAL_NO_SETTER
// [cfe] Setter not found: 'nextVar'.
this.nextVar = 1;
// ^^^^^^^
// [cfe] The setter 'nextVar' isn't defined for the class 'Example'.
// ^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.ASSIGNMENT_TO_FINAL_NO_SETTER
}
static test() {
nextVar = 0;
// ^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.ASSIGNMENT_TO_FINAL_NO_SETTER
// [cfe] Setter not found: 'nextVar'.
this.nextVar = 0;
// ^^^^
// [analyzer] COMPILE_TIME_ERROR.INVALID_REFERENCE_TO_THIS
// [cfe] Expected identifier, but got 'this'.
// ^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.ASSIGNMENT_TO_FINAL_NO_SETTER
}
}
class Example1 {
Example1(int i) {}
}
class Example2 extends Example1 {
static int _var = 1;
static int get nextVar => _var++;
Example2() : super(nextVar) {} // No 'this' in scope.
}
void main() {
Example x = new Example();
Example.test();
Example2 x2 = new Example2();
}