xp-framework / compiler

Compiles future PHP to today's PHP.
19 stars 0 forks source link

Interop with xp-forge/partial broken #15

Closed thekid closed 7 years ago

thekid commented 7 years ago

Dynamic traits cannot be resolved, resulting in Cannot instantiate incomplete type com\example\user\lang\partial\Value

thekid commented 7 years ago

Fix:

--- src/main/php/lang/ast/Parse.class.php       2017-10-31 17:30:56.570161100 +0100
+++ src/main/php/lang/ast/Parse.class.php.new   2017-10-31 17:30:46.244551200 +0100
@@ -402,19 +402,23 @@
       $this->token= $this->advance();

       if ('{' === $this->token->symbol->id) {
+        $types= [];
         while ('}' !== $this->token->symbol->id) {
           $this->token= $this->advance();
           $class= $this->token->value;
+          $types[]= $import.$class;
           $this->scope->import($import.$class);
           $this->token= $this->advance();
         }
         $this->token= $this->advance();
       } else {
+        $types= [$import];
         $this->scope->import($import);
       }

       $this->token= $this->expect(';');
       $node->arity= 'import';
+      $node->value= $types;
       return $node;
     });

--- src/main/php/lang/ast/Emitter.class.php     2017-10-31 17:31:04.758931100 +0100
+++ src/main/php/lang/ast/Emitter.class.php.new 2017-10-31 17:31:01.913885000 +0100
@@ -189,11 +189,11 @@
   }

   protected function emitPackage($node) {
-    $this->out->write('namespace '.$node->value.";\n");
+    $this->out->write('namespace '.$node->value.';');
   }

   protected function emitImport($node) {
-    // NOOP
+    $this->out->write('use '.implode(',', $node->value).';');
   }

   protected function emitAnnotation($node) {
thekid commented 7 years ago

Maybe this should be part of the compiler itself?

use lang\partial\Value;

class User is Value {
  // ..
}

This would call e.g. $node= \lang\ast\Is::transform($node, 'Value').

More complex matter => RFC needed