Skip to content

Commit

Permalink
Merge pull request #539 from nkt/bugfix/multiply-interface-extending
Browse files Browse the repository at this point in the history
Allow multiple interface extending
  • Loading branch information
Phalcon committed Sep 17, 2014
2 parents 3508e65 + f23ec05 commit b272b2a
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Library/ClassDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public function setIsAbstract($abstract)
*/
public function isAbstract()
{
return $this->abstract;
return $this->abstract || $this->isInterface();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Library/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*/
class Compiler
{
const VERSION = '0.5.0a';
const VERSION = '0.5.1a';

/**
* @var CompilerFile[]
Expand Down
5 changes: 4 additions & 1 deletion Library/CompilerFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,10 @@ public function preCompileInterface($namespace, $topStatement)
$classDefinition = new ClassDefinition($namespace, $topStatement['name']);

if (isset($topStatement['extends'])) {
$classDefinition->setExtendsClass($this->getFullName($topStatement['extends']));
foreach ($topStatement['extends'] as &$extend) {

This comment has been minimized.

Copy link
@mruz

mruz Sep 22, 2014

Contributor

I'm getting error:

PHP Warning: Invalid argument supplied for foreach() in ../vendor/phalcon/zephir/Library/CompilerFile.php on line 203
PHP Catchable fatal error: Argument 1 passed to Zephir\ClassDefinition::setImplementsInterfaces() must be of the type array, string given, called in ../vendor/phalcon/zephir/Library/CompilerFile.php on line 206 and defined in ../vendor/phalcon/zephir/Library/ClassDefinition.php on line 249

This comment has been minimized.

Copy link
@nkt

nkt Sep 22, 2014

Contributor

Did you compile parser and run zephir fullclean?

This comment has been minimized.

Copy link
@mruz

mruz Sep 22, 2014

Contributor

No, just run zephir fullclean, so I'll try to recompile parser.
After recompiling parser the error is gone. Thanks

$extend['value'] = $this->getFullName($extend['value']);
}
$classDefinition->setImplementsInterfaces($topStatement['extends']);
}

$classDefinition->setType('interface');
Expand Down
1 change: 1 addition & 0 deletions ext/config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ if test "$PHP_TEST" = "yes"; then
test/exceptions.zep.c
test/exists.zep.c
test/exitdie.zep.c
test/extendedinterface.zep.c
test/factorial.zep.c
test/fannkuch.zep.c
test/fcall.zep.c
Expand Down
2 changes: 1 addition & 1 deletion ext/php_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#define PHP_TEST_VERSION "1.0.0"
#define PHP_TEST_EXTNAME "test"
#define PHP_TEST_AUTHOR "Zephir Team and contributors"
#define PHP_TEST_ZEPVERSION "0.4.6a"
#define PHP_TEST_ZEPVERSION "0.5.0a"
#define PHP_TEST_DESCRIPTION "Description test for<br/>Test Extension"

typedef struct _zephir_struct_test {
Expand Down
2 changes: 2 additions & 0 deletions ext/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "kernel/memory.h"

zend_class_entry *test_diinterface_ce;
zend_class_entry *test_extendedinterface_ce;
zend_class_entry *test_methodinterface_ce;
zend_class_entry *test_testinterface_ce;
zend_class_entry *test_constantsparent_ce;
Expand Down Expand Up @@ -302,6 +303,7 @@ static PHP_MINIT_FUNCTION(test)
#endif

ZEPHIR_INIT(Test_DiInterface);
ZEPHIR_INIT(Test_ExtendedInterface);
ZEPHIR_INIT(Test_MethodInterface);
ZEPHIR_INIT(Test_TestInterface);
ZEPHIR_INIT(Test_ConstantsParent);
Expand Down
1 change: 1 addition & 0 deletions ext/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "test/exceptions.zep.h"
#include "test/exists.zep.h"
#include "test/exitdie.zep.h"
#include "test/extendedinterface.zep.h"
#include "test/factorial.zep.h"
#include "test/fannkuch.zep.h"
#include "test/fcall.zep.h"
Expand Down
24 changes: 24 additions & 0 deletions ext/test/extendedinterface.zep.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions ext/test/extendedinterface.zep.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions parser/parser.lemon
Original file line number Diff line number Diff line change
Expand Up @@ -232,15 +232,15 @@ static json_object *xx_ret_class(xx_parser_token *T, json_object *class_definiti
return ret;
}

static json_object *xx_ret_interface(xx_parser_token *T, json_object *interface_definition, xx_parser_token *E, xx_scanner_state *state)
static json_object *xx_ret_interface(xx_parser_token *T, json_object *interface_definition, json_object *extends_list, xx_scanner_state *state)
{
json_object *ret = json_object_new_object();

json_object_object_add(ret, "type", json_object_new_string("interface"));
json_object_object_add(ret, "name", json_object_new_string(T->token));

if (E) {
json_object_object_add(ret, "extends", json_object_new_string(E->token));
if (extends_list) {
json_object_object_add(ret, "extends", extends_list);
}

if (interface_definition) {
Expand Down Expand Up @@ -1258,8 +1258,8 @@ xx_interface_def(R) ::= INTERFACE IDENTIFIER(I) xx_interface_body(B) . {
R = xx_ret_interface(I, B, NULL, status->scanner_state);
}

xx_interface_def(R) ::= INTERFACE IDENTIFIER(I) EXTENDS IDENTIFIER(E) xx_interface_body(B) . {
R = xx_ret_interface(I, B, E, status->scanner_state);
xx_interface_def(R) ::= INTERFACE IDENTIFIER(I) EXTENDS xx_implements_list(L) xx_interface_body(B) . {
R = xx_ret_interface(I, B, L, status->scanner_state);
}

xx_class_def(R) ::= CLASS IDENTIFIER(I) xx_class_body(B) . {
Expand Down
6 changes: 6 additions & 0 deletions test/extendedinterface.zep
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Test;

interface ExtendedInterface extends \IteratorAggregate, \Countable
{

}
31 changes: 31 additions & 0 deletions unit-tests/Extension/ExtendedInterfaceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

/*
+--------------------------------------------------------------------------+
| Zephir Language |
+--------------------------------------------------------------------------+
| Copyright (c) 2013-2014 Zephir Team and contributors |
+--------------------------------------------------------------------------+
| This source file is subject the MIT license, that is bundled with |
| this package in the file LICENSE, and is available through the |
| world-wide-web at the following url: |
| http://zephir-lang.com/license.html |
| |
| If you did not receive a copy of the MIT license and are unable |
| to obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+--------------------------------------------------------------------------+
*/

namespace Extension;

class ExtendedInterfaceTest extends \PHPUnit_Framework_TestCase
{
public function testCheckInterfaceExtending()
{
$refl = new \ReflectionClass('Test\\ExtendedInterface');
$this->assertTrue($refl->isInterface());
$this->assertContains('IteratorAggregate', $refl->getInterfaceNames());
$this->assertContains('Countable', $refl->getInterfaceNames());
}
}

0 comments on commit b272b2a

Please sign in to comment.