mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 02:07:06 +00:00
[vm] Update @ResourceIdentifier check to account for source library
As otherwise another class used as an annotation could be mistakenly accounted for here. TEST=pkg/vm/testcases/transformations/resource_identifier/different.dart Change-Id: I39f6dd60f8bb4077b40ef5e999a7c9f28f70eb82 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/350361 Reviewed-by: Moritz Sümmermann <mosum@google.com> Reviewed-by: Daco Harkes <dacoharkes@google.com> Commit-Queue: Daco Harkes <dacoharkes@google.com> Reviewed-by: Jens Johansen <jensj@google.com>
This commit is contained in:
parent
fe0e0775c2
commit
c11af25403
|
@ -16,17 +16,21 @@ import '../messages.dart'
|
|||
messageResourceIdentifiersMultiple;
|
||||
import 'constant_evaluator.dart' show ErrorReporter;
|
||||
|
||||
/// Get all annotations for the given [node] of the form
|
||||
/// `@ResourceIdentifier(...)`
|
||||
/// Get all of the `@ResourceIdentifier` annotations from `package:meta`
|
||||
/// that are attached to the specified [node].
|
||||
Iterable<InstanceConstant> findResourceAnnotations(Annotatable node) =>
|
||||
node.annotations
|
||||
.whereType<ConstantExpression>()
|
||||
.map((expression) => expression.constant)
|
||||
.whereType<InstanceConstant>()
|
||||
.where((instance) => isResourceIdentifier(instance.classNode));
|
||||
.where((instance) => isResourceIdentifier(instance.classNode))
|
||||
.toList(growable: false);
|
||||
|
||||
final Uri _metaLibraryUri = new Uri(scheme: 'package', path: 'meta/meta.dart');
|
||||
|
||||
bool isResourceIdentifier(Class classNode) =>
|
||||
classNode.name == 'ResourceIdentifier';
|
||||
classNode.name == 'ResourceIdentifier' &&
|
||||
classNode.enclosingLibrary.importUri == _metaLibraryUri;
|
||||
|
||||
/// Report if the resource annotations is placed on anything but a static
|
||||
/// method.
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
// 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.
|
||||
|
||||
void main() {
|
||||
print(SomeClass.someStaticMethod(42));
|
||||
}
|
||||
|
||||
class SomeClass {
|
||||
@ResourceIdentifier('id')
|
||||
static someStaticMethod(int i) {
|
||||
return i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
class ResourceIdentifier {
|
||||
final Object? metadata;
|
||||
|
||||
const ResourceIdentifier([this.metadata]);
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
library #lib;
|
||||
import self as self;
|
||||
import "dart:core" as core;
|
||||
|
||||
abstract class SomeClass extends core::Object {
|
||||
[@vm.unboxing-info.metadata=()->i] static method someStaticMethod() → dynamic {
|
||||
return [@vm.direct-call.metadata=dart.core::_IntegerImplementation.+] [@vm.inferred-type.metadata=int (skip check)] #C1.{core::num::+}(1){(core::num) → core::int};
|
||||
}
|
||||
}
|
||||
static method main() → void {
|
||||
core::print([@vm.inferred-type.metadata=int] self::SomeClass::someStaticMethod());
|
||||
}
|
||||
constants {
|
||||
#C1 = 42
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"_comment": "Resources referenced by annotated resource identifiers",
|
||||
"AppTag": "TBD",
|
||||
"environment": {
|
||||
"dart.tool.dart2js": false
|
||||
},
|
||||
"identifiers": []
|
||||
}
|
Loading…
Reference in a new issue