[VM] Use UserVisibleName for types in error messages reported to users to make the error more clear. This fixes the case in issue 33303.
Bug: 33303
Change-Id: Idd31eadea3d2caca1cc9416b3286d39102bc2108
Reviewed-on: https://dart-review.googlesource.com/57880
Reviewed-by: RĂ©gis Crelier <regis@google.com>
Commit-Queue: Siva Annamalai <asiva@google.com>
diff --git a/runtime/vm/compiler/frontend/kernel_binary_flowgraph.cc b/runtime/vm/compiler/frontend/kernel_binary_flowgraph.cc
index 3b72081..501c73f 100644
--- a/runtime/vm/compiler/frontend/kernel_binary_flowgraph.cc
+++ b/runtime/vm/compiler/frontend/kernel_binary_flowgraph.cc
@@ -3894,11 +3894,12 @@
const AbstractType& type = T.BuildType();
if (!type.IsInstantiated() || type.IsMalformed()) {
+ const String& type_str = String::Handle(type.UserVisibleName());
H.ReportError(
script_, TokenPosition::kNoSource,
"Not a constant expression: right hand side of an implicit "
"as-expression is expected to be an instantiated type, got %s",
- type.ToCString());
+ type_str.ToCString());
}
const TypeArguments& instantiator_type_arguments = TypeArguments::Handle();
@@ -3906,9 +3907,13 @@
Error& error = Error::Handle();
if (!result_.IsInstanceOf(type, instantiator_type_arguments,
function_type_arguments, &error)) {
+ const AbstractType& rtype =
+ AbstractType::Handle(result_.GetType(Heap::kNew));
+ const String& result_str = String::Handle(rtype.UserVisibleName());
+ const String& type_str = String::Handle(type.UserVisibleName());
H.ReportError(script_, TokenPosition::kNoSource,
"Not a constant expression: %s is not an instance of %s",
- result_.ToCString(), type.ToCString());
+ result_str.ToCString(), type_str.ToCString());
}
}