-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change-Id: I823582328b4b9cc63ac734e9ea1c9354175a6e18 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/153880 Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
- Loading branch information
1 parent
b0b957f
commit dfdc7e4
Showing
5 changed files
with
130 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
pkg/analyzer/test/src/diagnostics/private_setter_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
// Copyright (c) 2020, 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. | ||
|
||
import 'package:analyzer/src/error/codes.dart'; | ||
import 'package:test_reflective_loader/test_reflective_loader.dart'; | ||
|
||
import '../dart/resolution/driver_resolution.dart'; | ||
|
||
main() { | ||
defineReflectiveSuite(() { | ||
defineReflectiveTests(PrivateSetterTest); | ||
}); | ||
} | ||
|
||
@reflectiveTest | ||
class PrivateSetterTest extends DriverResolutionTest { | ||
test_typeLiteral_privateField_differentLibrary() async { | ||
newFile('/test/lib/a.dart', content: r''' | ||
class A { | ||
static int _foo = 0; | ||
} | ||
'''); | ||
await assertErrorsInCode(r''' | ||
import 'a.dart'; | ||
main() { | ||
A._foo = 0; | ||
} | ||
''', [ | ||
error(CompileTimeErrorCode.PRIVATE_SETTER, 31, 4), | ||
]); | ||
|
||
var aImport = findElement.importFind('package:test/a.dart'); | ||
assertElement( | ||
findNode.simple('_foo = 0'), | ||
aImport.setter('_foo'), | ||
); | ||
} | ||
|
||
test_typeLiteral_privateField_sameLibrary() async { | ||
await assertNoErrorsInCode(r''' | ||
class A { | ||
// ignore:unused_field | ||
static int _foo = 0; | ||
} | ||
main() { | ||
A._foo = 0; | ||
} | ||
'''); | ||
} | ||
|
||
test_typeLiteral_privateSetter__sameLibrary() async { | ||
await assertNoErrorsInCode(r''' | ||
class A { | ||
static set _foo(int _) {} | ||
} | ||
main() { | ||
A._foo = 0; | ||
} | ||
'''); | ||
} | ||
|
||
test_typeLiteral_privateSetter_differentLibrary_hasGetter() async { | ||
newFile('/test/lib/a.dart', content: r''' | ||
class A { | ||
static set _foo(int _) {} | ||
static int get _foo => 0; | ||
} | ||
'''); | ||
await assertErrorsInCode(r''' | ||
import 'a.dart'; | ||
main() { | ||
A._foo = 0; | ||
} | ||
''', [ | ||
error(CompileTimeErrorCode.PRIVATE_SETTER, 31, 4), | ||
]); | ||
|
||
var aImport = findElement.importFind('package:test/a.dart'); | ||
assertElement( | ||
findNode.simple('_foo = 0'), | ||
aImport.setter('_foo'), | ||
); | ||
} | ||
|
||
test_typeLiteral_privateSetter_differentLibrary_noGetter() async { | ||
newFile('/test/lib/a.dart', content: r''' | ||
class A { | ||
static set _foo(int _) {} | ||
} | ||
'''); | ||
await assertErrorsInCode(r''' | ||
import 'a.dart'; | ||
main() { | ||
A._foo = 0; | ||
} | ||
''', [ | ||
error(CompileTimeErrorCode.PRIVATE_SETTER, 31, 4), | ||
]); | ||
|
||
var aImport = findElement.importFind('package:test/a.dart'); | ||
assertElement( | ||
findNode.simple('_foo = 0'), | ||
aImport.setter('_foo'), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters