2
0
Vladislav Folts 11 жил өмнө
parent
commit
ad455e717b
2 өөрчлөгдсөн 14 нэмэгдсэн , 0 устгасан
  1. 5 0
      src/context.js
  2. 9 0
      test/test_unit.js

+ 5 - 0
src/context.js

@@ -1604,6 +1604,11 @@ exports.RecordDecl = ChainedContext.extend({
             this.parent().exportField(field.id());
     },
     setBaseType: function(type){
+        if (!(type instanceof Type.Record))
+            throw new Errors.Error(
+                "RECORD type is expected as a base type, got '"
+                + type.description()
+                + "'");
         if (isTypeRecursive(type, this.__type))
             throw new Errors.Error("recursive inheritance: '"
                 + this.__type.name() + "'");

+ 9 - 0
test/test_unit.js

@@ -307,6 +307,15 @@ var testSuite = {
          ["T = RECORD r: RECORD (T) END END", "recursive field definition: 'r'"]
          )
     ),
+"record extension": testWithContext(
+    context(Grammar.typeDeclaration,
+            "TYPE B = RECORD END;"),
+    pass("T = RECORD(B) END"
+         ),
+    fail(["T = RECORD(INTEGER) END", "RECORD type is expected as a base type, got 'INTEGER'"],
+         ["T = RECORD(INTEGER) m: INTEGER END", "RECORD type is expected as a base type, got 'INTEGER'"]
+         )
+    ),
 "array declaration": testWithContext(
     context(Grammar.typeDeclaration,
             "CONST c1 = 5; VAR v1: INTEGER; p: POINTER TO RECORD END;"),