[dart2wasm] Improve wasm:class-id pragma error messages

Change-Id: Id9d073557738548d41e6fd90d8973d8e5d5c0748
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/318920
Reviewed-by: Joshua Litt <joshualitt@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
This commit is contained in:
Ömer Sinan Ağacan 2023-08-08 15:39:27 +00:00 committed by Commit Queue
parent b53e0b31ca
commit e61c6dc620

View file

@ -547,14 +547,18 @@ class Intrinsifier {
Member target = node.target; Member target = node.target;
// ClassID getters // ClassID getters
String? className = translator.getPragma(target, "wasm:class-id"); String? libAndClassName = translator.getPragma(target, "wasm:class-id");
if (className != null) { if (libAndClassName != null) {
List<String> libAndClass = className.split("#"); List<String> libAndClassNameParts = libAndClassName.split("#");
final String lib = libAndClassNameParts[0];
final String className = libAndClassNameParts[1];
Class cls = translator.libraries Class cls = translator.libraries
.firstWhere( .firstWhere((l) => l.name == lib && l.importUri.scheme == 'dart',
(l) => l.name == libAndClass[0] && l.importUri.scheme == 'dart') orElse: () => throw 'Library $lib not found (${target.location})')
.classes .classes
.firstWhere((c) => c.name == libAndClass[1]); .firstWhere((c) => c.name == className,
orElse: () => throw 'Class $className not found in library $lib '
'(${target.location})');
int classId = translator.classInfo[cls]!.classId; int classId = translator.classInfo[cls]!.classId;
b.i64_const(classId); b.i64_const(classId);
return w.NumType.i64; return w.NumType.i64;