Bladeren bron

fix: Fix a type casting bug with arrays

Fix a bug that prevented real arrays to receive integer values and vice-versa
Fix a bug with babel that replaced error messages in internal Error subclasses
Lucas de Souza 2 jaren geleden
bovenliggende
commit
62e35a0d0b

+ 1 - 1
js/ast/error/syntaxError.js

@@ -1,6 +1,6 @@
 export class SyntaxError extends Error {
   constructor (msg, id) {
-    super(...msg);
+    super(msg);
     this.id = id;
     this._context = {};
     if (Error.captureStackTrace) Error.captureStackTrace(this, SyntaxError);

+ 2 - 2
js/processor/error/runtimeError.js

@@ -1,7 +1,8 @@
 export class RuntimeError extends Error {
   constructor (msg, id) {
-    super(...msg);
+    super(msg);
     this.id = id;
+    this._context = {};
     if (Error.captureStackTrace) Error.captureStackTrace(this, RuntimeError);
   }
 
@@ -13,4 +14,3 @@ export class RuntimeError extends Error {
     this._context = contextObj;
   }
 }
-

+ 2 - 2
js/processor/error/semanticError.js

@@ -1,7 +1,8 @@
 export class SemanticError extends Error {
   constructor (msg, id) {
-    super(...msg);
+    super(msg);
     this.id = id;
+    this._context = {};
     if (Error.captureStackTrace) Error.captureStackTrace(this, SemanticError);
   }
 
@@ -13,4 +14,3 @@ export class SemanticError extends Error {
     this._context = contextObj;
   }
 }
-

+ 7 - 4
js/processor/semantic/semanticAnalyser.js

@@ -573,8 +573,8 @@ export class SemanticAnalyser {
       const access_type = typeInfo.type;
 
       let compatible = false;
+      let type = access_type;
       if (exp_type instanceof MultiType) {
-        let type = access_type;
         if (access_type.dimensions - used_dims == 0) {
           type = access_type.innerType;
         } else {
@@ -588,9 +588,12 @@ export class SemanticAnalyser {
         compatible = access_type.canAccept(exp_type, used_dims);
       }
       if (!compatible) {
+        if (0 === access_type.dimensions - used_dims) {
+          type = access_type.innerType; // enable a valid attempt to cast real <--> integer
+        }
         if (
           !Config.enable_type_casting ||
-          !Store.canImplicitTypeCast(access_type, exp_type)
+          !Store.canImplicitTypeCast(type, exp_type)
         ) {
           const access_type_string_info = access_type.stringInfo();
           const access_type_info = access_type_string_info[0];
@@ -918,7 +921,7 @@ export class SemanticAnalyser {
             (!resultType.isCompatible(Types.INTEGER) &&
               !resultType.isCompatible(Types.REAL)) ||
             formalParam.type.isCompatible(Types.INTEGER) ||
-              formalParam.type.isCompatible(Types.REAL)
+            formalParam.type.isCompatible(Types.REAL)
           ) {
             throw ProcessorErrorFactory.invalid_parameter_type_full(
               fun.name,
@@ -935,7 +938,7 @@ export class SemanticAnalyser {
             (!resultType.isCompatible(Types.INTEGER) &&
               !resultType.isCompatible(Types.REAL)) ||
             formalParam.type.isCompatible(Types.INTEGER) ||
-              formalParam.type.isCompatible(Types.REAL)
+            formalParam.type.isCompatible(Types.REAL)
           ) {
             throw ProcessorErrorFactory.invalid_parameter_type_full(
               fun.name,