8000 Declare defaultImplementations inside InType scope · xp-framework/compiler@588ff38 · GitHub
[go: up one dir, main page]

Skip to content

Commit 588ff38

Browse files
committed
Declare defaultImplementations inside InType scope
See #151 (comment)
1 parent 0575e8a commit 588ff38

File tree

2 files changed

+4
-9
lines changed

2 files changed

+4
-9
lines changed

src/main/php/lang/ast/emit/InType.class.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class InType {
66
public $init= [];
77
public $statics= [];
88
public $virtual= [];
9+
public $defaultImplementations= [];
910

1011
public function __construct($type) {
1112
$this->type= $type;

src/main/php/lang/ast/emit/PHP.class.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -553,10 +553,10 @@ protected function emitInterface($result, $interface) {
553553
$this->emitMeta($result, $interface->name, $interface->annotations, $interface->comment);
554554

555555
// Emit default implementations
556-
if (isset($result->locals[3])) {
556+
if ($defaults= $result->codegen->scope[0]->defaultImplementations) {
557557
$p= strrpos($interface->name, '\\');
558558
$name= substr($interface->name, 0, $p).'\\__'.substr($interface->name, $p + 1).'_Defaults';
559-
$this->emitOne($result, new TraitDeclaration([], new IsValue($name), $result->locals[3]));
559+
$this->emitOne($result, new TraitDeclaration([], new IsValue($name), $defaults));
560560
}
561561

562562
$result->codegen->leave();
@@ -670,10 +670,9 @@ protected function emitMethod($result, $method) {
670670

671671
if (null === $method->body) {
672672
$result->out->write(';');
673-
$default= null;
674673
} else if ('interface' === $result->codegen->scope[0]->type->kind) {
675674
$result->out->write(';');
676-
$default= $method;
675+
$result->codegen->scope[0]->defaultImplementations[]= $method;
677676
} else {
678677
$result->out->write(' {');
679678

@@ -697,18 +696,13 @@ protected function emitMethod($result, $method) {
697696

698697
$this->emitAll($result, $method->body);
699698
$result->out->write('}');
700-
$default= null;
701699
}
702700

703701
foreach ($promoted as $param) {
704702
$this->emitProperty($result, new Property(explode(' ', $param->promote), $param->name, $param->type));
705703
}
706704

707705
$result->locals= array_pop($result->stack);
708-
709-
// Copy default implementations to class scope
710-
$default && $result->locals[3][]= $default;
711-
712706
$result->codegen->scope[0]->meta[self::METHOD][$method->name]= $meta;
713707
}
714708

0 commit comments

Comments
 (0)
0