Ver Fonte

Fix NIL in ternary operator.

Vladislav Folts há 9 anos atrás
pai
commit
d4671c431b
3 ficheiros alterados com 16 adições e 3 exclusões
  1. BIN
      bin/compiled.zip
  2. 4 0
      src/eberon/EberonContextExpression.ob
  3. 12 3
      test/test_unit_eberon.js

BIN
bin/compiled.zip


+ 4 - 0
src/eberon/EberonContextExpression.ob

@@ -194,6 +194,10 @@ BEGIN
             resultType := findCommonBase(firstType, secondType);
         ELSIF (firstType IS Record.PPointer) & (secondType IS Record.PPointer) THEN
             resultType := EberonContextDesignator.makePointer(findCommonBase(Record.pointerBase(firstType^), Record.pointerBase(secondType^)));
+        ELSIF (firstType = Types.nil) & (secondType IS Record.PPointer) THEN
+            resultType := secondType;
+        ELSIF (secondType = Types.nil) & (firstType IS Record.PPointer) THEN
+            resultType := firstType;
         END;
 
         IF resultType = NIL THEN 

+ 12 - 3
test/test_unit_eberon.js

@@ -1516,7 +1516,8 @@ exports.suite = {
     },
 "ternary operator": testWithContext(
         context(grammar.expression,
-                "TYPE Base = RECORD END; PBase = POINTER TO Base; Derived = RECORD(Base) END;"
+                "TYPE Base = RECORD END; PBase = POINTER TO Base;"
+                    + "Derived = RECORD(Base) END; PDerived = POINTER TO Derived;"
                     + "Derived2 = RECORD(Base) END; Derived3 = RECORD(Base) END;" 
                 + "VAR b: BOOLEAN; i1, i2: INTEGER; s: STRING; byte: BYTE;"
                 + "rb: Base; rd: Derived; rd2: Derived2; rd3: Derived3;"
@@ -1524,6 +1525,7 @@ exports.suite = {
                 + "PROCEDURE passBase(b: Base): BOOLEAN; RETURN TRUE END;"
                 + "PROCEDURE passDerived(d: Derived): BOOLEAN; RETURN TRUE END;"
                 + "PROCEDURE passPBase(p: PBase): BOOLEAN; RETURN TRUE END;"
+                + "PROCEDURE passPDerived(p: PDerived): BOOLEAN; RETURN TRUE END;"
                 ),
         pass("b ? i1 : i2",
              "(b ? i1 : i2) # 0",
@@ -1532,6 +1534,8 @@ exports.suite = {
              "b ? byte : i1",
              "b ? pb : pd",
              "b ? pd : pb",
+             "b ? pb : NIL",
+             "b ? NIL : pb",
              "passBase(b ? pb^ : pd^)",
              "passBase(b ? pd^ : pb^)",
              "passBase(b ? pd2^ : pd3^)",
@@ -1540,7 +1544,9 @@ exports.suite = {
              "passBase(b ? rd2 : rd3)",
              "b ? i1 : b ? i1 : i2",
              "passPBase(b ? pb : pd)",
-             "passPBase(b ? pd : pb)"
+             "passPBase(b ? pd : pb)",
+             "passPBase(b ? pb : NIL)",
+             "passPBase(b ? NIL : pb)"
              ),
         fail(["b ?", "not parsed"],
              ["b ? i1", "expected \":\" after \"?\" in ternary operator"],
@@ -1549,7 +1555,10 @@ exports.suite = {
              ["passBase(b ? pb^ : pd)", "incompatible types in ternary operator: 'Base' and 'POINTER TO Derived'"],
              ["passDerived(b ? pb : pd)", "type mismatch for argument 1: 'POINTER TO Base' cannot be converted to 'Derived'"],
              ["passDerived(b ? pd : pb)", "type mismatch for argument 1: 'POINTER TO Base' cannot be converted to 'Derived'"],
-             ["b ? b ? i1 : i2 : i1", "expected \":\" after \"?\" in ternary operator"]
+             ["b ? b ? i1 : i2 : i1", "expected \":\" after \"?\" in ternary operator"],
+             ["b ? rb : NIL", "incompatible types in ternary operator: 'Base' and 'NIL'"],
+             ["passPDerived(b ? NIL : pb)", "type mismatch for argument 1: 'PBase' cannot be converted to 'PDerived'"],
+             ["passPDerived(b ? pb : NIL)", "type mismatch for argument 1: 'PBase' cannot be converted to 'PDerived'"]
              )
     )
 };