mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 00:19:48 +00:00
[test] Convert most lib/mirrors multitests to static error tests
Change-Id: I4f3b728a94291bf0a31a5f38af9d8b877a9900af Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/363702 Reviewed-by: Bob Nystrom <rnystrom@google.com> Commit-Queue: William Hesse <whesse@google.com>
This commit is contained in:
parent
d6c9c9f8bf
commit
c10ecb8fe5
|
@ -401,7 +401,9 @@ class StaticError implements Comparable<StaticError> {
|
|||
// Ignore column and length for unspecified errors.
|
||||
if (isSpecified) {
|
||||
if (column != actual.column) return false;
|
||||
if (actual.length > 0 && length != actual.length) return false;
|
||||
if (actual.length > 0 && length > 0 && length != actual.length) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
@ -50,6 +50,10 @@ main() {
|
|||
|
||||
var f4 = B4;
|
||||
var f5 = B5;
|
||||
f6(const p1) {}
|
||||
// ^^^^^
|
||||
// [analyzer] SYNTACTIC_ERROR.EXTRANEOUS_MODIFIER
|
||||
// [cfe] Can't have modifier 'const' here.
|
||||
}
|
||||
|
||||
const F0 = 42;
|
||||
|
|
60
tests/lib/mirrors/metadata_allowed_values_runtime_test.dart
Normal file
60
tests/lib/mirrors/metadata_allowed_values_runtime_test.dart
Normal file
|
@ -0,0 +1,60 @@
|
|||
// Copyright (c) 2024, 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 'dart:mirrors';
|
||||
import 'package:expect/expect.dart';
|
||||
|
||||
import 'metadata_allowed_values_import.dart'; // Unprefixed.
|
||||
import 'metadata_allowed_values_import.dart' as prefix;
|
||||
|
||||
@B.CONSTANT
|
||||
class B {
|
||||
static const CONSTANT = 3;
|
||||
}
|
||||
|
||||
@C(3)
|
||||
class C {
|
||||
final field;
|
||||
const C(this.field);
|
||||
}
|
||||
|
||||
@D.named(4)
|
||||
class D {
|
||||
final field;
|
||||
const D.named(this.field);
|
||||
}
|
||||
|
||||
@Imported()
|
||||
class N {}
|
||||
|
||||
@Imported.named()
|
||||
class O {}
|
||||
|
||||
@Imported.CONSTANT
|
||||
class P {}
|
||||
|
||||
@prefix.Imported()
|
||||
class R {}
|
||||
|
||||
@prefix.Imported.named()
|
||||
class S {}
|
||||
|
||||
@prefix.Imported.CONSTANT
|
||||
class T {}
|
||||
|
||||
checkMetadata(DeclarationMirror mirror, List expectedMetadata) {
|
||||
Expect.listEquals(expectedMetadata.map(reflect).toList(), mirror.metadata);
|
||||
}
|
||||
|
||||
main() {
|
||||
checkMetadata(reflectClass(B), [B.CONSTANT]);
|
||||
checkMetadata(reflectClass(C), [const C(3)]);
|
||||
checkMetadata(reflectClass(D), [const D.named(4)]);
|
||||
checkMetadata(reflectClass(N), [const Imported()]);
|
||||
checkMetadata(reflectClass(O), [const Imported.named()]);
|
||||
checkMetadata(reflectClass(P), [Imported.CONSTANT]);
|
||||
checkMetadata(reflectClass(R), [const prefix.Imported()]);
|
||||
checkMetadata(reflectClass(S), [const prefix.Imported.named()]);
|
||||
checkMetadata(reflectClass(T), [prefix.Imported.CONSTANT]);
|
||||
}
|
|
@ -5,130 +5,232 @@
|
|||
library test.metadata_allowed_values;
|
||||
|
||||
import 'dart:mirrors';
|
||||
// ^
|
||||
// [web] Dart library 'dart:mirrors' is not available on this platform.
|
||||
import 'package:expect/expect.dart';
|
||||
|
||||
import 'metadata_allowed_values_import.dart'; // Unprefixed.
|
||||
import 'metadata_allowed_values_import.dart' as prefix;
|
||||
|
||||
@A // //# 01: compile-time error
|
||||
@A
|
||||
// ^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.NON_CONSTANT_ANNOTATION_CONSTRUCTOR
|
||||
// ^
|
||||
// [cfe] This can't be used as an annotation; an annotation should be a reference to a compile-time constant variable, or a call to a constant constructor.
|
||||
class A {}
|
||||
|
||||
@B.CONSTANT
|
||||
class B {
|
||||
static const CONSTANT = 3;
|
||||
}
|
||||
|
||||
@C(3)
|
||||
class C {
|
||||
final field;
|
||||
const C(this.field);
|
||||
}
|
||||
|
||||
@D.named(4)
|
||||
class D {
|
||||
final field;
|
||||
const D.named(this.field);
|
||||
}
|
||||
|
||||
@E.NOT_CONSTANT // //# 02: compile-time error
|
||||
@E.NOT_CONSTANT
|
||||
// ^^^^^^^^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.INVALID_ANNOTATION
|
||||
// ^
|
||||
// [cfe] Constant evaluation error:
|
||||
class E {
|
||||
static var NOT_CONSTANT = 3;
|
||||
}
|
||||
|
||||
@F(6) // //# 03: compile-time error
|
||||
@F(6)
|
||||
// ^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.NON_CONSTANT_ANNOTATION_CONSTRUCTOR
|
||||
// ^
|
||||
// [cfe] Cannot invoke a non-'const' constructor where a const expression is expected.
|
||||
class F {
|
||||
final field;
|
||||
F(this.field);
|
||||
}
|
||||
|
||||
@G.named(4) // //# 04: compile-time error
|
||||
@G.named(4)
|
||||
// ^^^^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.NON_CONSTANT_ANNOTATION_CONSTRUCTOR
|
||||
// ^
|
||||
// [cfe] Cannot invoke a non-'const' constructor where a const expression is expected.
|
||||
class G {
|
||||
final field;
|
||||
G.named(this.field);
|
||||
}
|
||||
|
||||
@I[0] // //# 06: compile-time error
|
||||
@I[0]
|
||||
//^
|
||||
// [analyzer] SYNTACTIC_ERROR.EXPECTED_EXECUTABLE
|
||||
// [cfe] Expected a declaration, but got '['.
|
||||
// ^
|
||||
// [analyzer] SYNTACTIC_ERROR.EXPECTED_EXECUTABLE
|
||||
// [cfe] Expected a declaration, but got '0'.
|
||||
// ^
|
||||
// [analyzer] SYNTACTIC_ERROR.EXPECTED_EXECUTABLE
|
||||
// [cfe] Expected a declaration, but got ']'.
|
||||
class I {}
|
||||
|
||||
@this.toString // //# 07: compile-time error
|
||||
@this.toString
|
||||
// ^^^^^^^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_ANNOTATION
|
||||
// ^^^^
|
||||
// [analyzer] SYNTACTIC_ERROR.EXPECTED_IDENTIFIER_BUT_GOT_KEYWORD
|
||||
// [cfe] 'this' can't be used as an identifier because it's a keyword.
|
||||
// ^
|
||||
// [cfe] Member not found: 'this.toString'.
|
||||
// [cfe] This can't be used as an annotation; an annotation should be a reference to a compile-time constant variable, or a call to a constant constructor.
|
||||
class J {}
|
||||
|
||||
@super.toString // //# 08: compile-time error
|
||||
@super.toString
|
||||
// ^^^^^^^^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_ANNOTATION
|
||||
// ^^^^^
|
||||
// [analyzer] SYNTACTIC_ERROR.EXPECTED_IDENTIFIER_BUT_GOT_KEYWORD
|
||||
// [cfe] 'super' can't be used as an identifier because it's a keyword.
|
||||
// ^
|
||||
// [cfe] Member not found: 'super.toString'.
|
||||
// [cfe] This can't be used as an annotation; an annotation should be a reference to a compile-time constant variable, or a call to a constant constructor.
|
||||
class K {}
|
||||
|
||||
@L.func() // //# 09: compile-time error
|
||||
@L.func()
|
||||
// ^^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.INVALID_ANNOTATION
|
||||
// ^
|
||||
// [cfe] Couldn't find constructor 'L.func'.
|
||||
class L {
|
||||
static func() => 6;
|
||||
}
|
||||
|
||||
@Imported // //# 10: compile-time error
|
||||
@Imported
|
||||
// ^^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.NO_ANNOTATION_CONSTRUCTOR_ARGUMENTS
|
||||
// ^
|
||||
// [cfe] This can't be used as an annotation; an annotation should be a reference to a compile-time constant variable, or a call to a constant constructor.
|
||||
class M {}
|
||||
|
||||
@Imported()
|
||||
class N {}
|
||||
|
||||
@Imported.named()
|
||||
class O {}
|
||||
|
||||
@Imported.CONSTANT
|
||||
class P {}
|
||||
|
||||
@prefix.Imported // //# 11: compile-time error
|
||||
@prefix.Imported
|
||||
// ^^^^^^^^^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.NO_ANNOTATION_CONSTRUCTOR_ARGUMENTS
|
||||
// ^
|
||||
// [cfe] This can't be used as an annotation; an annotation should be a reference to a compile-time constant variable, or a call to a constant constructor.
|
||||
class Q {}
|
||||
|
||||
@prefix.Imported()
|
||||
class R {}
|
||||
|
||||
@prefix.Imported.named()
|
||||
class S {}
|
||||
|
||||
@prefix.Imported.CONSTANT
|
||||
class T {}
|
||||
|
||||
@U..toString() // //# 12: compile-time error
|
||||
@U..toString()
|
||||
// ^^
|
||||
// [analyzer] SYNTACTIC_ERROR.EXPECTED_EXECUTABLE
|
||||
// [cfe] Expected a declaration, but got '..'.
|
||||
class U {}
|
||||
// ^^^^^
|
||||
// [analyzer] SYNTACTIC_ERROR.MISSING_FUNCTION_BODY
|
||||
// [cfe] Expected '{' before this.
|
||||
|
||||
@V.tearOff // //# 13: compile-time error
|
||||
@V.tearOff
|
||||
// ^^^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.INVALID_ANNOTATION
|
||||
class V {
|
||||
static tearOff() {}
|
||||
}
|
||||
|
||||
topLevelTearOff() => 4;
|
||||
|
||||
@topLevelTearOff // //# 14: compile-time error
|
||||
@topLevelTearOff
|
||||
// ^^^^^^^^^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.INVALID_ANNOTATION
|
||||
class W {}
|
||||
|
||||
@TypeParameter // //# 15: compile-time error
|
||||
@TypeParameter
|
||||
// ^^^^^^^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_ANNOTATION
|
||||
// ^
|
||||
// [cfe] This can't be used as an annotation; an annotation should be a reference to a compile-time constant variable, or a call to a constant constructor.
|
||||
// [cfe] Undefined name 'TypeParameter'.
|
||||
class X<TypeParameter> {}
|
||||
|
||||
@TypeParameter.member // //# 16: compile-time error
|
||||
@TypeParameter.member
|
||||
// ^^^^^^^^^^^^^^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_ANNOTATION
|
||||
// ^
|
||||
// [cfe] Member not found: 'TypeParameter.member'.
|
||||
// [cfe] This can't be used as an annotation; an annotation should be a reference to a compile-time constant variable, or a call to a constant constructor.
|
||||
class Y<TypeParameter> {}
|
||||
|
||||
@1 // //# 17: compile-time error
|
||||
@1
|
||||
// [error column 4]
|
||||
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_ANNOTATION
|
||||
// ^
|
||||
// [analyzer] SYNTACTIC_ERROR.MISSING_IDENTIFIER
|
||||
// [cfe] Expected an identifier, but got '1'.
|
||||
class Z {}
|
||||
|
||||
@3.14 // //# 18: compile-time error
|
||||
@3.14
|
||||
// [error column 4]
|
||||
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_ANNOTATION
|
||||
// ^^^^
|
||||
// [analyzer] SYNTACTIC_ERROR.MISSING_IDENTIFIER
|
||||
// [cfe] Expected an identifier, but got '3.14'.
|
||||
class AA {}
|
||||
|
||||
@'string' // //# 19: compile-time error
|
||||
@'string'
|
||||
// [error column 4]
|
||||
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_ANNOTATION
|
||||
// ^^^^^^^^
|
||||
// [analyzer] SYNTACTIC_ERROR.MISSING_IDENTIFIER
|
||||
// [cfe] Expected an identifier, but got ''string''.
|
||||
class BB {}
|
||||
|
||||
@#symbol // //# 20: compile-time error
|
||||
@#symbol
|
||||
// ^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_ANNOTATION
|
||||
// ^
|
||||
// [analyzer] SYNTACTIC_ERROR.MISSING_IDENTIFIER
|
||||
// [cfe] Expected an identifier, but got '#'.
|
||||
// ^^^^^^
|
||||
// [analyzer] SYNTACTIC_ERROR.EXPECTED_TOKEN
|
||||
// [analyzer] SYNTACTIC_ERROR.MISSING_CONST_FINAL_VAR_OR_TYPE
|
||||
// [cfe] Expected ';' after this.
|
||||
// [cfe] This can't be used as an annotation; an annotation should be a reference to a compile-time constant variable, or a call to a constant constructor.
|
||||
// [cfe] This couldn't be parsed.
|
||||
// [cfe] Variables must be declared using the keywords 'const', 'final', 'var' or a type name.
|
||||
class CC {}
|
||||
|
||||
@['element'] // //# 21: compile-time error
|
||||
@['element']
|
||||
// ^
|
||||
// [analyzer] SYNTACTIC_ERROR.MISSING_IDENTIFIER
|
||||
// [cfe] Expected an identifier, but got '['.
|
||||
// ^^^^^^^^^
|
||||
// [analyzer] SYNTACTIC_ERROR.EXPECTED_EXECUTABLE
|
||||
// [cfe] Expected a declaration, but got ''element''.
|
||||
// ^
|
||||
// [analyzer] SYNTACTIC_ERROR.EXPECTED_EXECUTABLE
|
||||
// [cfe] Expected a declaration, but got ']'.
|
||||
class DD {}
|
||||
|
||||
@{'key': 'value'} // //# 22: compile-time error
|
||||
@{'key': 'value'}
|
||||
// ^
|
||||
// [analyzer] SYNTACTIC_ERROR.EXPECTED_EXECUTABLE
|
||||
// [analyzer] SYNTACTIC_ERROR.MISSING_IDENTIFIER
|
||||
// [cfe] Expected a declaration, but got '{'.
|
||||
// [cfe] Expected an identifier, but got '{'.
|
||||
class EE {}
|
||||
|
||||
@true // //# 23: compile-time error
|
||||
@true
|
||||
// ^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_ANNOTATION
|
||||
// ^^^^
|
||||
// [analyzer] SYNTACTIC_ERROR.EXPECTED_IDENTIFIER_BUT_GOT_KEYWORD
|
||||
// [cfe] 'true' can't be used as an identifier because it's a keyword.
|
||||
// [cfe] This can't be used as an annotation; an annotation should be a reference to a compile-time constant variable, or a call to a constant constructor.
|
||||
// [cfe] Undefined name 'true'.
|
||||
class FF {}
|
||||
|
||||
@false // //# 24: compile-time error
|
||||
@false
|
||||
// ^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_ANNOTATION
|
||||
// ^^^^^
|
||||
// [analyzer] SYNTACTIC_ERROR.EXPECTED_IDENTIFIER_BUT_GOT_KEYWORD
|
||||
// [cfe] 'false' can't be used as an identifier because it's a keyword.
|
||||
// [cfe] This can't be used as an annotation; an annotation should be a reference to a compile-time constant variable, or a call to a constant constructor.
|
||||
// [cfe] Undefined name 'false'.
|
||||
class GG {}
|
||||
|
||||
@null // //# 25: compile-time error
|
||||
@null
|
||||
// ^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_ANNOTATION
|
||||
// ^^^^
|
||||
// [analyzer] SYNTACTIC_ERROR.EXPECTED_IDENTIFIER_BUT_GOT_KEYWORD
|
||||
// [cfe] 'null' can't be used as an identifier because it's a keyword.
|
||||
// [cfe] This can't be used as an annotation; an annotation should be a reference to a compile-time constant variable, or a call to a constant constructor.
|
||||
// [cfe] Undefined name 'null'.
|
||||
class HH {}
|
||||
|
||||
const a = const [1, 2, 3];
|
||||
|
@ -136,83 +238,70 @@ const a = const [1, 2, 3];
|
|||
@a
|
||||
class II {}
|
||||
|
||||
@a[0] // //# 26: compile-time error
|
||||
@a[0]
|
||||
//^
|
||||
// [analyzer] SYNTACTIC_ERROR.EXPECTED_EXECUTABLE
|
||||
// [cfe] Expected a declaration, but got '['.
|
||||
// ^
|
||||
// [analyzer] SYNTACTIC_ERROR.EXPECTED_EXECUTABLE
|
||||
// [cfe] Expected a declaration, but got '0'.
|
||||
// ^
|
||||
// [analyzer] SYNTACTIC_ERROR.EXPECTED_EXECUTABLE
|
||||
// [cfe] Expected a declaration, but got ']'.
|
||||
class JJ {}
|
||||
|
||||
@kk // //# 27: compile-time error
|
||||
@kk
|
||||
// ^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.INVALID_ANNOTATION
|
||||
// ^
|
||||
// [cfe] Constant evaluation error:
|
||||
class KK {
|
||||
const KK();
|
||||
}
|
||||
|
||||
get kk => const KK();
|
||||
|
||||
@LL(() => 42) // //# 28: compile-time error
|
||||
@LL(() => 42)
|
||||
// ^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_WITH_NON_CONSTANT_ARGUMENT
|
||||
// [cfe] Not a constant expression.
|
||||
class LL {
|
||||
final field;
|
||||
const LL(this.field);
|
||||
}
|
||||
|
||||
@MM((x) => 42) // //# 29: compile-time error
|
||||
@MM((x) => 42)
|
||||
// ^^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_WITH_NON_CONSTANT_ARGUMENT
|
||||
// [cfe] Not a constant expression.
|
||||
class MM {
|
||||
final field;
|
||||
const MM(this.field);
|
||||
}
|
||||
|
||||
@NN(() {}) // //# 30: compile-time error
|
||||
@NN(() {})
|
||||
// ^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_WITH_NON_CONSTANT_ARGUMENT
|
||||
// [cfe] Not a constant expression.
|
||||
class NN {
|
||||
final field;
|
||||
const NN(this.field);
|
||||
}
|
||||
|
||||
@OO(() { () {} }) // //# 31: compile-time error
|
||||
@OO(() { () {} })
|
||||
// ^^^^^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_WITH_NON_CONSTANT_ARGUMENT
|
||||
// [cfe] Not a constant expression.
|
||||
// ^
|
||||
// [cfe] Not a constant expression.
|
||||
// ^
|
||||
// [analyzer] SYNTACTIC_ERROR.EXPECTED_TOKEN
|
||||
// [cfe] Expected ';' after this.
|
||||
class OO {
|
||||
final field;
|
||||
const OO(this.field);
|
||||
}
|
||||
|
||||
checkMetadata(DeclarationMirror mirror, List expectedMetadata) {
|
||||
Expect.listEquals(expectedMetadata.map(reflect).toList(), mirror.metadata);
|
||||
}
|
||||
|
||||
main() {
|
||||
reflectClass(A).metadata;
|
||||
checkMetadata(reflectClass(B), [B.CONSTANT]);
|
||||
checkMetadata(reflectClass(C), [const C(3)]);
|
||||
checkMetadata(reflectClass(D), [const D.named(4)]);
|
||||
reflectClass(E).metadata;
|
||||
reflectClass(F).metadata;
|
||||
reflectClass(G).metadata;
|
||||
reflectClass(I).metadata;
|
||||
reflectClass(J).metadata;
|
||||
reflectClass(K).metadata;
|
||||
reflectClass(L).metadata;
|
||||
reflectClass(M).metadata;
|
||||
checkMetadata(reflectClass(N), [const Imported()]);
|
||||
checkMetadata(reflectClass(O), [const Imported.named()]);
|
||||
checkMetadata(reflectClass(P), [Imported.CONSTANT]);
|
||||
reflectClass(Q).metadata;
|
||||
checkMetadata(reflectClass(R), [const prefix.Imported()]);
|
||||
checkMetadata(reflectClass(S), [const prefix.Imported.named()]);
|
||||
checkMetadata(reflectClass(T), [prefix.Imported.CONSTANT]);
|
||||
reflectClass(U).metadata;
|
||||
reflectClass(V).metadata;
|
||||
reflectClass(W).metadata;
|
||||
reflectClass(X).metadata;
|
||||
reflectClass(Y).metadata;
|
||||
reflectClass(Z).metadata;
|
||||
reflectClass(AA).metadata;
|
||||
reflectClass(BB).metadata;
|
||||
reflectClass(CC).metadata;
|
||||
reflectClass(DD).metadata;
|
||||
reflectClass(EE).metadata;
|
||||
reflectClass(FF).metadata;
|
||||
reflectClass(GG).metadata;
|
||||
reflectClass(HH).metadata;
|
||||
reflectClass(II).metadata;
|
||||
reflectClass(JJ).metadata;
|
||||
reflectClass(KK).metadata;
|
||||
reflectClass(LL).metadata;
|
||||
reflectClass(MM).metadata;
|
||||
reflectClass(NN).metadata;
|
||||
reflectClass(OO).metadata;
|
||||
}
|
||||
main() {}
|
||||
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
// Copyright (c) 2024, 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.
|
||||
|
||||
// Regression test for Issue 13817.
|
||||
|
||||
import 'dart:mirrors';
|
||||
import 'package:expect/expect.dart';
|
||||
|
||||
class Tag {
|
||||
final name;
|
||||
const Tag({named}) : this.name = named;
|
||||
}
|
||||
|
||||
@Tag(named: 'valid')
|
||||
class B {}
|
||||
|
||||
@Tag(named: C.STATIC_FIELD)
|
||||
class C {
|
||||
static const STATIC_FIELD = 3;
|
||||
}
|
||||
|
||||
checkMetadata(DeclarationMirror mirror, List expectedMetadata) {
|
||||
Expect.listEquals(expectedMetadata.map(reflect).toList(), mirror.metadata);
|
||||
}
|
||||
|
||||
main() {
|
||||
checkMetadata(reflectClass(B), [const Tag(named: 'valid')]);
|
||||
checkMetadata(reflectClass(C), [const Tag(named: C.STATIC_FIELD)]);
|
||||
}
|
|
@ -4,8 +4,6 @@
|
|||
|
||||
// Regression test for Issue 13817.
|
||||
|
||||
library test.metadata_constructor_arguments;
|
||||
|
||||
import 'dart:mirrors';
|
||||
import 'package:expect/expect.dart';
|
||||
|
||||
|
@ -14,59 +12,66 @@ class Tag {
|
|||
const Tag({named}) : this.name = named;
|
||||
}
|
||||
|
||||
@Tag(named: undefined) // //# 01: compile-time error
|
||||
@Tag(named: undefined)
|
||||
// ^^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_WITH_NON_CONSTANT_ARGUMENT
|
||||
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_IDENTIFIER
|
||||
// [cfe] Undefined name 'undefined'.
|
||||
class A {}
|
||||
|
||||
@Tag(named: 'valid')
|
||||
class B {}
|
||||
|
||||
@Tag(named: C.STATIC_FIELD)
|
||||
class C {
|
||||
static const STATIC_FIELD = 3;
|
||||
}
|
||||
|
||||
@Tag(named: D.instanceMethod()) // //# 02: compile-time error
|
||||
@Tag(named: D.instanceMethod())
|
||||
// ^^^^^^^^^^^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_METHOD_INVOCATION
|
||||
// ^^^^^^^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.STATIC_ACCESS_TO_INSTANCE_MEMBER
|
||||
// [cfe] Member not found: 'D.instanceMethod'.
|
||||
class D {
|
||||
instanceMethod() {}
|
||||
}
|
||||
|
||||
@Tag(named: instanceField) // //# 03: compile-time error
|
||||
@Tag(named: instanceField)
|
||||
// ^^^^^^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_WITH_NON_CONSTANT_ARGUMENT
|
||||
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_IDENTIFIER
|
||||
// [cfe] Undefined name 'instanceField'.
|
||||
class E {
|
||||
var instanceField;
|
||||
}
|
||||
|
||||
@Tag(named: F.nonConstStaticField) // //# 04: compile-time error
|
||||
@Tag(named: F.nonConstStaticField)
|
||||
// [error column 2]
|
||||
// [cfe] Constant evaluation error:
|
||||
// ^^^^^^^^^^^^^^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_WITH_NON_CONSTANT_ARGUMENT
|
||||
class F {
|
||||
static var nonConstStaticField = 6;
|
||||
}
|
||||
|
||||
@Tag(named: instanceMethod) // //# 05: compile-time error
|
||||
@Tag(named: instanceMethod)
|
||||
// ^^^^^^^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_WITH_NON_CONSTANT_ARGUMENT
|
||||
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_IDENTIFIER
|
||||
// [cfe] Undefined name 'instanceMethod'.
|
||||
class G {
|
||||
instanceMethod() {}
|
||||
}
|
||||
|
||||
@Tag(named: this) // //# 06: compile-time error
|
||||
@Tag(named: this)
|
||||
// ^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_WITH_NON_CONSTANT_ARGUMENT
|
||||
// [analyzer] COMPILE_TIME_ERROR.INVALID_REFERENCE_TO_THIS
|
||||
// [cfe] Expected identifier, but got 'this'.
|
||||
class H {
|
||||
instanceMethod() {}
|
||||
}
|
||||
|
||||
@Tag(named: super) // //# 07: compile-time error
|
||||
@Tag(named: super)
|
||||
// ^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_WITH_NON_CONSTANT_ARGUMENT
|
||||
// [analyzer] COMPILE_TIME_ERROR.SUPER_IN_INVALID_CONTEXT
|
||||
// [cfe] Expected identifier, but got 'super'.
|
||||
class I {
|
||||
instanceMethod() {}
|
||||
}
|
||||
|
||||
checkMetadata(DeclarationMirror mirror, List expectedMetadata) {
|
||||
Expect.listEquals(expectedMetadata.map(reflect).toList(), mirror.metadata);
|
||||
}
|
||||
|
||||
main() {
|
||||
reflectClass(A).metadata;
|
||||
checkMetadata(reflectClass(B), [const Tag(named: 'valid')]);
|
||||
checkMetadata(reflectClass(C), [const Tag(named: C.STATIC_FIELD)]);
|
||||
reflectClass(D).metadata;
|
||||
reflectClass(E).metadata;
|
||||
reflectClass(F).metadata;
|
||||
reflectClass(G).metadata;
|
||||
reflectClass(H).metadata;
|
||||
reflectClass(I).metadata;
|
||||
}
|
||||
main() {}
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
// Copyright (c) 2024, 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.
|
||||
|
||||
// Regression test for Issue 17141.
|
||||
|
||||
import 'dart:mirrors';
|
||||
import 'package:expect/expect.dart';
|
||||
|
||||
class Box {
|
||||
final contents;
|
||||
const Box([this.contents]);
|
||||
}
|
||||
|
||||
class MutableBox {
|
||||
var contents;
|
||||
MutableBox([this.contents]); // Not const.
|
||||
}
|
||||
|
||||
@Box()
|
||||
class A {}
|
||||
|
||||
@Box(const Box())
|
||||
class B {}
|
||||
|
||||
@Box(const Box(const Box()))
|
||||
class C {}
|
||||
|
||||
@Box(Box())
|
||||
class F {}
|
||||
|
||||
@Box(Box(const Box()))
|
||||
class G {}
|
||||
|
||||
final closure = () => 42;
|
||||
|
||||
function() => 42;
|
||||
|
||||
// N.B. This is legal, but @function is not (tested by metadata_allowed_values).
|
||||
@Box(function)
|
||||
class M {}
|
||||
|
||||
checkMetadata(DeclarationMirror mirror, List expectedMetadata) {
|
||||
Expect.listEquals(expectedMetadata.map(reflect).toList(), mirror.metadata);
|
||||
}
|
||||
|
||||
main() {
|
||||
closure();
|
||||
checkMetadata(reflectClass(A), [const Box()]);
|
||||
checkMetadata(reflectClass(B), [const Box(const Box())]);
|
||||
checkMetadata(reflectClass(C), [const Box(const Box(const Box()))]);
|
||||
reflectClass(F).metadata;
|
||||
reflectClass(G).metadata;
|
||||
reflectClass(M).metadata;
|
||||
}
|
|
@ -4,10 +4,7 @@
|
|||
|
||||
// Regression test for Issue 17141.
|
||||
|
||||
library test.metadata_nested_constructor_call;
|
||||
|
||||
import 'dart:mirrors';
|
||||
import 'package:expect/expect.dart';
|
||||
|
||||
class Box {
|
||||
final contents;
|
||||
|
@ -19,67 +16,60 @@ class MutableBox {
|
|||
MutableBox([this.contents]); // Not const.
|
||||
}
|
||||
|
||||
@Box()
|
||||
class A {}
|
||||
|
||||
@Box(const Box())
|
||||
class B {}
|
||||
|
||||
@Box(const Box(const Box()))
|
||||
class C {}
|
||||
|
||||
@Box(const Box(const MutableBox())) // //# 01: compile-time error
|
||||
@Box(const Box(const MutableBox()))
|
||||
// ^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_WITH_NON_CONST
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_WITH_NON_CONSTANT_ARGUMENT
|
||||
// ^
|
||||
// [cfe] Cannot invoke a non-'const' constructor where a const expression is expected.
|
||||
class D {}
|
||||
|
||||
@Box(const MutableBox(const Box())) // //# 02: compile-time error
|
||||
@Box(const MutableBox(const Box()))
|
||||
// ^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_WITH_NON_CONST
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_WITH_NON_CONSTANT_ARGUMENT
|
||||
// ^
|
||||
// [cfe] Cannot invoke a non-'const' constructor where a const expression is expected.
|
||||
class E {}
|
||||
|
||||
@Box(Box())
|
||||
class F {}
|
||||
|
||||
@Box(Box(const Box()))
|
||||
class G {}
|
||||
|
||||
@Box(Box(const MutableBox())) // //# 05: compile-time error
|
||||
@Box(Box(const MutableBox()))
|
||||
// ^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_WITH_NON_CONST
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_WITH_NON_CONSTANT_ARGUMENT
|
||||
// ^
|
||||
// [cfe] Cannot invoke a non-'const' constructor where a const expression is expected.
|
||||
class H {}
|
||||
|
||||
@Box(MutableBox(const Box())) // //# 06: compile-time error
|
||||
@Box(MutableBox(const Box()))
|
||||
// ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_WITH_NON_CONST
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_WITH_NON_CONSTANT_ARGUMENT
|
||||
// [cfe] Cannot invoke a non-'const' constructor where a const expression is expected.
|
||||
class I {}
|
||||
|
||||
final closure = () => 42;
|
||||
|
||||
@Box(closure()) // //# 07: compile-time error
|
||||
@Box(closure())
|
||||
// ^^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_WITH_NON_CONSTANT_ARGUMENT
|
||||
// [cfe] Method invocation is not a constant expression.
|
||||
// [cfe] Not a constant expression.
|
||||
class J {}
|
||||
|
||||
@Box(closure) // //# 08: compile-time error
|
||||
@Box(closure)
|
||||
// [error column 2]
|
||||
// [cfe] Constant evaluation error:
|
||||
// ^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_WITH_NON_CONSTANT_ARGUMENT
|
||||
// [cfe] Not a constant expression.
|
||||
class K {}
|
||||
|
||||
function() => 42;
|
||||
|
||||
@Box(function()) // //# 09: compile-time error
|
||||
@Box(function())
|
||||
// ^^^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.CONST_EVAL_METHOD_INVOCATION
|
||||
// [cfe] Method invocation is not a constant expression.
|
||||
class L {}
|
||||
|
||||
// N.B. This is legal, but @function is not (tested by metadata_allowed_values).
|
||||
@Box(function)
|
||||
class M {}
|
||||
|
||||
checkMetadata(DeclarationMirror mirror, List expectedMetadata) {
|
||||
Expect.listEquals(expectedMetadata.map(reflect).toList(), mirror.metadata);
|
||||
}
|
||||
|
||||
main() {
|
||||
closure();
|
||||
checkMetadata(reflectClass(A), [const Box()]);
|
||||
checkMetadata(reflectClass(B), [const Box(const Box())]);
|
||||
checkMetadata(reflectClass(C), [const Box(const Box(const Box()))]);
|
||||
reflectClass(D).metadata;
|
||||
reflectClass(E).metadata;
|
||||
reflectClass(F).metadata;
|
||||
reflectClass(G).metadata;
|
||||
reflectClass(H).metadata;
|
||||
reflectClass(I).metadata;
|
||||
reflectClass(J).metadata;
|
||||
reflectClass(K).metadata;
|
||||
reflectClass(L).metadata;
|
||||
reflectClass(M).metadata;
|
||||
}
|
||||
main() {}
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
// Copyright (c) 2013, 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.
|
||||
|
||||
library test.parameter_is_const;
|
||||
|
||||
import 'dart:mirrors';
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
|
||||
class Class {
|
||||
foo(
|
||||
const //# 01: compile-time error
|
||||
param) {}
|
||||
}
|
||||
|
||||
main() {
|
||||
MethodMirror mm = reflectClass(Class).declarations[#foo] as MethodMirror;
|
||||
Expect.isFalse(mm.parameters.single.isConst);
|
||||
}
|
|
@ -2,12 +2,6 @@
|
|||
// 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.
|
||||
|
||||
// This tests uses the multi-test "ok" feature:
|
||||
// none: Desired behaviour, passing on the VM.
|
||||
// 01: Trimmed version for dart2js.
|
||||
//
|
||||
// TODO(rmacnak,ahe): Remove multi-test when VM and dart2js are on par.
|
||||
|
||||
/** Test of [ParameterMirror]. */
|
||||
library test.parameter_test;
|
||||
|
||||
|
@ -88,9 +82,6 @@ main() {
|
|||
expect('Class(s(B) in s(test.parameter_test), top-level)',
|
||||
barConstructor.returnType);
|
||||
|
||||
// dart2js stops testing here.
|
||||
return; // //# 01: ok
|
||||
|
||||
MethodMirror bazConstructor = constructors[#B.baz] as MethodMirror;
|
||||
expect('Method(s(B.baz) in s(B), constructor)', bazConstructor);
|
||||
expect(
|
||||
|
|
|
@ -12,6 +12,7 @@ import 'stringify.dart';
|
|||
|
||||
class Foo {
|
||||
static String bar = '...';
|
||||
static const int biz = 5;
|
||||
String aux = '';
|
||||
static foo() {}
|
||||
baz() {}
|
||||
|
@ -27,4 +28,6 @@ void main() {
|
|||
reflectClass(Foo).declarations[new Symbol('foo')]);
|
||||
expect('Variable(s(bar) in s(Foo), static)',
|
||||
reflectClass(Foo).declarations[new Symbol('bar')]);
|
||||
expect('Variable(s(biz) in s(Foo), static, final, const)',
|
||||
reflectClass(Foo).declarations[new Symbol('biz')]);
|
||||
}
|
||||
|
|
|
@ -62,6 +62,7 @@ void writeVariableOn(VariableMirror variable, StringBuffer buffer) {
|
|||
writeDeclarationOn(variable, buffer);
|
||||
if (variable.isStatic) buffer.write(', static');
|
||||
if (variable.isFinal) buffer.write(', final');
|
||||
if (variable.isConst) buffer.write(', const');
|
||||
}
|
||||
|
||||
String stringifyVariable(VariableMirror variable) {
|
||||
|
|
Loading…
Reference in a new issue