2
0
Эх сурвалжийг харах

Fix for checking instantiation of record with having methods.

Vladislav Folts 11 жил өмнө
parent
commit
9fa6c44862

+ 8 - 6
src/eberon/eberon_context.js

@@ -112,6 +112,7 @@ var RecordType = Type.Record.extend({
         this.__finalized = false;
         this.__declaredMethods = {};
         this.__definedMethods = [];
+        this.__abstractMethods = [];
         this.__instantiated = false;
         this.__lazyDefinitions = [];
         this.__nonExportedMethods = [];
@@ -179,20 +180,21 @@ var RecordType = Type.Record.extend({
         else if (this.__lazyDefinitions.indexOf(id) == -1)
             this.__lazyDefinitions.push(id);
     },
-    abstractMethods: function(){
+    abstractMethods: function(){return this.__abstractMethods;},
+    __collectAbstractMethods: function(){
+        var selfMethods = Object.keys(this.__declaredMethods);
         var baseType = this.baseType();
-        var methods = baseType ? baseType.abstractMethods().concat(Object.keys(this.__declaredMethods))
-                               : Object.keys(this.__declaredMethods);
-        var result = [];
+        var methods = baseType ? baseType.abstractMethods().concat(selfMethods)
+                               : selfMethods;
         for(var i = 0; i < methods.length; ++i){
             var m = methods[i];
             if (this.__definedMethods.indexOf(m) == -1)
-                result.push(m);
+                this.__abstractMethods.push(m);
         }
-        return result;
     },
     finalize: function(){
         this.__finalized = true;
+        this.__collectAbstractMethods();
         if (this.__instantiated)
             this.__ensureNonAbstract();
         this.__ensureMethodDefinitions(this.__lazyDefinitions);

+ 7 - 1
test/test_unit_eberon.js

@@ -25,6 +25,7 @@ exports.suite = {
 "abstract method declaration": testWithContext(
     context(grammar.declarationSequence, 
             "TYPE T = RECORD PROCEDURE p() END;"
+            + "D = RECORD(T) END;"
             + "T2 = RECORD PROCEDURE p1(); PROCEDURE p2(i: INTEGER): BOOLEAN END;"
             ),
     pass(),
@@ -33,7 +34,12 @@ exports.suite = {
          ["VAR r: T2;",
           "cannot instantiate 'T2' because it has abstract method(s): p1, p2"],
          ["PROCEDURE p(); VAR p: POINTER TO T; BEGIN NEW(p); END p;",
-          "cannot instantiate 'T' because it has abstract method(s): p"])
+          "cannot instantiate 'T' because it has abstract method(s): p"],
+         ["VAR r: D;",
+          "cannot instantiate 'D' because it has abstract method(s): p"],
+         ["PROCEDURE p(); VAR p: POINTER TO D; BEGIN NEW(p); END p;",
+          "cannot instantiate 'D' because it has abstract method(s): p"]
+        )
     ),
 "new method declaration": testWithContext(
     context(grammar.declarationSequence,