Browse Source

Fix a bug where a CompoundType could accept another of same dim

Lucas de Souza 6 years ago
parent
commit
0085ce7917

+ 0 - 2
js/processor/semantic/semanticAnalyser.js

@@ -214,8 +214,6 @@ export class SemanticAnalyser {
         literal.value.reduce((last, next) => {
           const eType = this.evaluateExpressionType(next);
           if (!last.canAccept(eType)) {
-            console.log(last);
-            console.log(eType);
             throw new Error("invalid value type for array");
           }
           return last;

+ 0 - 2
js/processor/store/store.js

@@ -54,8 +54,6 @@ export class Store {
         const oldType = oldObj.type;
         const stoType = stoObj.type;
         // TODO: better error message
-        console.log(oldObj);
-        console.log(stoObj);
         throw new Error(`${oldType} is not compatible with type ${stoType} given`);
       }
     }

+ 1 - 2
js/typeSystem/compoundType.js

@@ -20,8 +20,7 @@ export class CompoundType extends Type {
 
   canAccept (another) {
     if(another instanceof CompoundType) {
-      console.log("canAccept: another is compound");
-      return this.dimensions >= another.dimensions && this.innerType.isCompatible(another.innerType);
+      return this.dimensions > another.dimensions && this.innerType.isCompatible(another.innerType);
     } else {
       return this.innerType.isCompatible(another);
     }

+ 11 - 0
tests/test63.spec.js

@@ -0,0 +1,11 @@
+import { CompoundType } from "./../js/typeSystem/compoundType";
+import { Types } from "./../js/typeSystem/types";
+
+describe("A  CompoundType of an Int and dimension 1", () => {
+
+  it("should not accept another of same dimension", () => {
+    const t1 = new CompoundType(Types.INTEGER, 1);
+    const t2 = new CompoundType(Types.INTEGER, 1);
+    expect(t1.canAccept(t2)).toBeFalsy();
+  });
+});