nsresolver fails on TraitUse without adaptations

This commit is contained in:
z7zmey 2018-06-14 00:29:48 +03:00
parent bfc346ebab
commit a98301f940
2 changed files with 23 additions and 15 deletions

View File

@ -156,6 +156,7 @@ func (nsr *NamespaceResolver) EnterNode(w walker.Walkable) bool {
nsr.ResolveName(t, "") nsr.ResolveName(t, "")
} }
if n.TraitAdaptationList != nil {
for _, a := range n.TraitAdaptationList.Adaptations { for _, a := range n.TraitAdaptationList.Adaptations {
switch aa := a.(type) { switch aa := a.(type) {
case *stmt.TraitUsePrecedence: case *stmt.TraitUsePrecedence:
@ -174,7 +175,7 @@ func (nsr *NamespaceResolver) EnterNode(w walker.Walkable) bool {
} }
} }
} }
}
} }
return true return true

View File

@ -348,6 +348,7 @@ func TestResolveGroupUse(t *testing.T) {
func TestResolveTraitUse(t *testing.T) { func TestResolveTraitUse(t *testing.T) {
nameAB := &name.Name{Parts: []node.Node{&name.NamePart{Value: "A"}, &name.NamePart{Value: "B"}}} nameAB := &name.Name{Parts: []node.Node{&name.NamePart{Value: "A"}, &name.NamePart{Value: "B"}}}
nameB := &name.Name{Parts: []node.Node{&name.NamePart{Value: "B"}}} nameB := &name.Name{Parts: []node.Node{&name.NamePart{Value: "B"}}}
nameD := &name.Name{Parts: []node.Node{&name.NamePart{Value: "D"}}}
fullyQualifiedNameB := &name.FullyQualified{Parts: []node.Node{&name.NamePart{Value: "B"}}} fullyQualifiedNameB := &name.FullyQualified{Parts: []node.Node{&name.NamePart{Value: "B"}}}
fullyQualifiedNameBC := &name.FullyQualified{Parts: []node.Node{&name.NamePart{Value: "B"}, &name.NamePart{Value: "C"}}} fullyQualifiedNameBC := &name.FullyQualified{Parts: []node.Node{&name.NamePart{Value: "B"}, &name.NamePart{Value: "C"}}}
@ -387,11 +388,17 @@ func TestResolveTraitUse(t *testing.T) {
}, },
}, },
}, },
&stmt.TraitUse{
Traits: []node.Node{
nameD,
},
},
}, },
} }
expected := map[node.Node]string{ expected := map[node.Node]string{
nameB: "A\\B", nameB: "A\\B",
nameD: "D",
relativeNameB: "B", relativeNameB: "B",
fullyQualifiedNameB: "B", fullyQualifiedNameB: "B",
fullyQualifiedNameBC: "B\\C", fullyQualifiedNameBC: "B\\C",