diff --git a/phpunit/src/DuplicateTest.php b/phpunit/src/DuplicateTest.php index 767ef6ee..5653c11c 100644 --- a/phpunit/src/DuplicateTest.php +++ b/phpunit/src/DuplicateTest.php @@ -13,6 +13,7 @@ class DuplicateTest extends TestCase $compiler = CompilerTest::create(ROOT_PATH); $testFile = __DIR__ . '/../code/' . $file; $compiler->addFiles([$testFile]); + $compiler->prepare($testFile); $compiler->convert($testFile); } catch (TestError $exception) { $this->assertStringContainsString($expected, $exception->getMessage()); diff --git a/src/Php/Preprocessor.php b/src/Php/Preprocessor.php index b0221e11..3689c70a 100644 --- a/src/Php/Preprocessor.php +++ b/src/Php/Preprocessor.php @@ -197,7 +197,11 @@ class Preprocessor extends CompilerBase if ($this->stubFile) { $this->addFunction($name, $this->parseFunctionDecl($v)); } else { - $this->symbolDeclInFile[strtolower($name)] = $this->file; + $functionNameLower = strtolower($name); + if (isset($this->symbolDeclInFile[$functionNameLower])) { + $this->fatalError($v, "Duplicate function `{$functionNameLower}`"); + } + $this->symbolDeclInFile[$functionNameLower] = $this->file; } } @@ -227,6 +231,11 @@ class Preprocessor extends CompilerBase $this->symbolCallInFile[$this->file][] = $parentClassLower; } } + + if (isset($this->symbolDeclInFile[$fullClassNameLower])) { + $this->fatalError($class, "Duplicate class `{$fullClassName}`"); + } + $this->symbolDeclInFile[$fullClassNameLower] = $this->file; $code = '';