Annotation imports are not parsed for nested traits
Author: villermenCreated Apr 9, 2019Updated Jan 19, 2023
Labelsbug
Bug Report
When an entity uses a trait that itself also uses a trait with a doctrine annotation the mapper failes to recognize the imported annotation. Code example below if it's not clear.
| Q | A |
|---|---|
| BC Break | no |
| Version | 1.6.1 |
How to reproduce
Create the following class and traits using doctrine/orm:
// ClassA.php
use Doctrine\Orm\Mapping\Entity;
/**
* @Entity
*/
class ClassA
{
use TraitA;
}// TraitA.php
trait TraitA
{
use TraitB;
}// TraitB.php
use Doctrine\ORM\Mapping\Column;
trait TraitB
{
/**
* @Column(name="column", type="string")
*/
protected $column;
}Trying to create a mapping for this setup will throw an AnnotationException:
[Semantical Error] The annotation "@Column" in property Search\Model\ClassA::$column was never imported. Did you maybe forget to add a "use" statement for this annotation?This will fail on any Doctrine annotation that is used in TraitB but not imported in TraitA or ClassA.
I expect the @Column-annotation imported in TraitB to stay also be valid for ClassA where it ends up in.
Source: doctrine/annotations