Add column info for non-syntax errors where relatively precise

Should it also be added if only rough information is available? E.g.
spanning an entire class?
This commit is contained in:
Nikita Popov 2015-04-18 13:20:39 +02:00
parent 611fa5c7f1
commit 62f83a0dc2
10 changed files with 30 additions and 18 deletions

View File

@ -37,7 +37,7 @@ class Param extends NodeAbstract
$this->default = $default; $this->default = $default;
if ($variadic && null !== $default) { if ($variadic && null !== $default) {
throw new Error('Variadic parameter cannot have a default value'); throw new Error('Variadic parameter cannot have a default value', $default->getAttributes());
} }
} }

View File

@ -53,12 +53,18 @@ class Class_ extends ClassLike
} }
if (isset(self::$specialNames[(string) $this->extends])) { if (isset(self::$specialNames[(string) $this->extends])) {
throw new Error(sprintf('Cannot use \'%s\' as class name as it is reserved', $this->extends)); throw new Error(
sprintf('Cannot use \'%s\' as class name as it is reserved', $this->extends),
$this->extends->getAttributes()
);
} }
foreach ($this->implements as $interface) { foreach ($this->implements as $interface) {
if (isset(self::$specialNames[(string) $interface])) { if (isset(self::$specialNames[(string) $interface])) {
throw new Error(sprintf('Cannot use \'%s\' as interface name as it is reserved', $interface)); throw new Error(
sprintf('Cannot use \'%s\' as interface name as it is reserved', $interface),
$interface->getAttributes()
);
} }
} }
} }

View File

@ -37,7 +37,10 @@ class Interface_ extends ClassLike
foreach ($this->extends as $interface) { foreach ($this->extends as $interface) {
if (isset(self::$specialNames[(string) $interface])) { if (isset(self::$specialNames[(string) $interface])) {
throw new Error(sprintf('Cannot use \'%s\' as interface name as it is reserved', $interface)); throw new Error(
sprintf('Cannot use \'%s\' as interface name as it is reserved', $interface),
$interface->getAttributes()
);
} }
} }
} }

View File

@ -31,13 +31,16 @@ class Namespace_ extends Node\Stmt
$this->stmts = $stmts; $this->stmts = $stmts;
if (isset(self::$specialNames[(string) $this->name])) { if (isset(self::$specialNames[(string) $this->name])) {
throw new Error(sprintf('Cannot use \'%s\' as namespace name', $this->name)); throw new Error(
sprintf('Cannot use \'%s\' as namespace name', $this->name),
$this->name->getAttributes()
);
} }
if (null !== $this->stmts) { if (null !== $this->stmts) {
foreach ($this->stmts as $stmt) { foreach ($this->stmts as $stmt) {
if ($stmt instanceof self) { if ($stmt instanceof self) {
throw new Error('Namespace declarations cannot be nested', $stmt->getLine()); throw new Error('Namespace declarations cannot be nested', $stmt->getAttributes());
} }
} }
} }

View File

@ -1143,7 +1143,7 @@ class Parser extends ParserAbstract
} }
protected function reduceRule32($attributes) { protected function reduceRule32($attributes) {
throw new Error('__HALT_COMPILER() can only be used from the outermost scope'); throw new Error('__HALT_COMPILER() can only be used from the outermost scope', $attributes);
} }
protected function reduceRule33($attributes) { protected function reduceRule33($attributes) {

View File

@ -14,11 +14,11 @@ Syntax error, unexpected T_STATIC, expecting T_STRING from 1:12 to 1:17
----- -----
<?php class A extends self {} <?php class A extends self {}
----- -----
Cannot use 'self' as class name as it is reserved on line 1 Cannot use 'self' as class name as it is reserved from 1:22 to 1:25
----- -----
<?php class A extends parent {} <?php class A extends parent {}
----- -----
Cannot use 'parent' as class name as it is reserved on line 1 Cannot use 'parent' as class name as it is reserved from 1:22 to 1:27
----- -----
<?php class A extends static {} <?php class A extends static {}
----- -----
@ -26,11 +26,11 @@ Syntax error, unexpected T_STATIC, expecting T_STRING or T_NAMESPACE or T_NS_SEP
----- -----
<?php class A implements self {} <?php class A implements self {}
----- -----
Cannot use 'self' as interface name as it is reserved on line 1 Cannot use 'self' as interface name as it is reserved from 1:25 to 1:28
----- -----
<?php class A implements parent {} <?php class A implements parent {}
----- -----
Cannot use 'parent' as interface name as it is reserved on line 1 Cannot use 'parent' as interface name as it is reserved from 1:25 to 1:30
----- -----
<?php class A implements static {} <?php class A implements static {}
----- -----
@ -50,11 +50,11 @@ Syntax error, unexpected T_STATIC, expecting T_STRING from 1:16 to 1:21
----- -----
<?php interface A extends self {} <?php interface A extends self {}
----- -----
Cannot use 'self' as interface name as it is reserved on line 1 Cannot use 'self' as interface name as it is reserved from 1:26 to 1:29
----- -----
<?php interface A extends parent {} <?php interface A extends parent {}
----- -----
Cannot use 'parent' as interface name as it is reserved on line 1 Cannot use 'parent' as interface name as it is reserved from 1:26 to 1:31
----- -----
<?php interface A extends static {} <?php interface A extends static {}
----- -----

View File

@ -3,4 +3,4 @@ Invalid variadic function
<?php <?php
function foo(...$foo = []) {} function foo(...$foo = []) {}
----- -----
Variadic parameter cannot have a default value on line 2 Variadic parameter cannot have a default value from 2:23 to 2:24

View File

@ -5,4 +5,4 @@ if (true) {
__halt_compiler(); __halt_compiler();
} }
----- -----
__HALT_COMPILER() can only be used from the outermost scope on line 3 __HALT_COMPILER() can only be used from the outermost scope from 3:4 to 3:18

View File

@ -2,11 +2,11 @@ Invalid namespace names
----- -----
<?php namespace self; <?php namespace self;
----- -----
Cannot use 'self' as namespace name on line 1 Cannot use 'self' as namespace name from 1:16 to 1:19
----- -----
<?php namespace parent; <?php namespace parent;
----- -----
Cannot use 'parent' as namespace name on line 1 Cannot use 'parent' as namespace name from 1:16 to 1:21
----- -----
<?php namespace static; <?php namespace static;
----- -----

View File

@ -7,4 +7,4 @@ namespace A {
} }
} }
----- -----
Namespace declarations cannot be nested on line 3 Namespace declarations cannot be nested from 3:4 to 5:4