diff --git a/pkg/compiler/lib/src/serialization/element_serialization.dart b/pkg/compiler/lib/src/serialization/element_serialization.dart index 3182596edc2..7069b51ff56 100644 --- a/pkg/compiler/lib/src/serialization/element_serialization.dart +++ b/pkg/compiler/lib/src/serialization/element_serialization.dart @@ -8,6 +8,7 @@ import '../common.dart'; import '../constants/constructors.dart'; import '../constants/expressions.dart'; import '../dart_types.dart'; +import '../diagnostics/messages.dart'; import '../elements/elements.dart'; import '../elements/modelx.dart' show ErroneousElementX; import 'constant_serialization.dart'; @@ -213,8 +214,8 @@ class ErrorSerializer implements ElementSerializer { encoder.setEnum(Key.MESSAGE_KIND, element.messageKind); if (element.messageArguments.isNotEmpty) { MapEncoder mapEncoder = encoder.createMap(Key.ARGUMENTS); - element.messageArguments.forEach((String key, String value) { - mapEncoder.setString(key, value); + element.messageArguments.forEach((String key, var value) { + mapEncoder.setString(key, Message.convertToString(value)); }); } } diff --git a/pkg/compiler/lib/src/serialization/type_serialization.dart b/pkg/compiler/lib/src/serialization/type_serialization.dart index 3d4cb9fd353..24a46ae27f8 100644 --- a/pkg/compiler/lib/src/serialization/type_serialization.dart +++ b/pkg/compiler/lib/src/serialization/type_serialization.dart @@ -35,7 +35,9 @@ class TypeSerializer extends DartTypeVisitor { encoder.setTypes(Key.NAMED_PARAMETER_TYPES, type.namedParameterTypes); } - void visitMalformedType(MalformedType type, ObjectEncoder encoder) {} + void visitMalformedType(MalformedType type, ObjectEncoder encoder) { + encoder.setElement(Key.ELEMENT, type.element); + } void visitInterfaceType(InterfaceType type, ObjectEncoder encoder) { encoder.setElement(Key.ELEMENT, type.element); @@ -79,8 +81,11 @@ class TypeDeserializer { return new TypedefType(decoder.getElement(Key.ELEMENT), decoder.getTypes(Key.TYPE_ARGUMENTS, isOptional: true)); case TypeKind.STATEMENT: - case TypeKind.MALFORMED_TYPE: throw new UnsupportedError("Unexpected type kind '${typeKind}."); + case TypeKind.MALFORMED_TYPE: + // TODO(johnniwinther): Do we need the 'userProvidedBadType' or maybe + // just a toString of it? + return new MalformedType(decoder.getElement(Key.ELEMENT), null); case TypeKind.DYNAMIC: return const DynamicType(); case TypeKind.VOID: diff --git a/tests/compiler/dart2js/serialization/test_data.dart b/tests/compiler/dart2js/serialization/test_data.dart index 950a211e68a..562b21d7cf1 100644 --- a/tests/compiler/dart2js/serialization/test_data.dart +++ b/tests/compiler/dart2js/serialization/test_data.dart @@ -400,6 +400,20 @@ class A { noSuchMethod(_) => null; m(); } +''', + }), + + const Test('Malformed types', const { + 'main.dart': ''' +import 'a.dart'; + +main() { + m(); +} +''', + }, preserializedSourceFiles: const { + 'a.dart': ''' +Unresolved m() {} ''', }), ];