@@ -542,6 +542,11 @@ void AppendInlineExportFields(Module* module,
542
542
module ->AppendFields (fields);
543
543
}
544
544
545
+ bool IsIndexLikelyType (Index index) {
546
+ // TODO: Incorrect values can be misinterpreted by the parser.
547
+ return index >= static_cast <Index>(Type::Void);
548
+ }
549
+
545
550
} // End of anonymous namespace
546
551
547
552
WastParser::WastParser (WastLexer* lexer,
@@ -937,10 +942,10 @@ Result WastParser::ParseValueTypeList(TypeVector* out_type_list,
937
942
CHECK_RESULT (ParseValueType (&type));
938
943
939
944
if (type.is_index ()) {
940
- // TODO: Incorrect values can be misinterpreted by the parser.
941
- if (type.index () >= static_cast <Index>(Type::Void)) {
945
+ if (IsIndexLikelyType (type.index ())) {
942
946
out_type_list->push_back (Type (type.index ()));
943
947
} else {
948
+ type_vars->push_back (ReferenceVar (out_type_list->size (), type));
944
949
out_type_list->push_back (Type (Type::Reference, type.index ()));
945
950
}
946
951
} else {
@@ -1313,11 +1318,24 @@ Result WastParser::ResolveRefTypes(const Module& module,
1313
1318
1314
1319
assert (type.IsReferenceWithIndex ());
1315
1320
1321
+ if (ref_var.var .is_index ()) {
1322
+ if (type.GetReferenceIndex () >= module .types .size ()) {
1323
+ errors->emplace_back (
1324
+ ErrorLevel::Error, ref_var.var .loc ,
1325
+ StringPrintf (" reference type out of range: %d (max: %d)" ,
1326
+ static_cast <int >(type.GetReferenceIndex ()),
1327
+ static_cast <int >(module .types .size ())));
1328
+ result = Result::Error;
1329
+ }
1330
+ continue ;
1331
+ }
1332
+
1316
1333
if (type.GetReferenceIndex () != kInvalidIndex ) {
1334
+ // Resolved earlier.
1317
1335
continue ;
1318
1336
}
1319
1337
1320
- const auto type_index = module .type_bindings .FindIndex (ref_var.var .name ());
1338
+ Index type_index = module .type_bindings .FindIndex (ref_var.var .name ());
1321
1339
1322
1340
if (type_index == kInvalidIndex ) {
1323
1341
errors->emplace_back (ErrorLevel::Error, ref_var.var .loc ,
@@ -2057,7 +2075,12 @@ Result WastParser::ParseBoundValueTypeList(TokenType token,
2057
2075
bindings->emplace (name,
2058
2076
Binding (loc, binding_index_offset + types->size ()));
2059
2077
if (type.is_index ()) {
2060
- types->push_back (Type (type.index ()));
2078
+ if (IsIndexLikelyType (type.index ())) {
2079
+ types->push_back (Type (type.index ()));
2080
+ } else {
2081
+ type_vars->push_back (ReferenceVar (types->size (), type));
2082
+ types->push_back (Type (Type::Reference, type.index ()));
2083
+ }
2061
2084
} else {
2062
2085
assert (type.is_name ());
2063
2086
assert (options_->features .function_references_enabled ());
0 commit comments