php8: resolve union types in NamespaceResolver

This commit is contained in:
Tyler Christensen 2023-04-24 12:25:31 -06:00 committed by Laytan Laats
parent 5baa28bb27
commit 3c45afd848
2 changed files with 14 additions and 0 deletions

View File

@ -278,6 +278,12 @@ func (nsr *NamespaceResolver) ResolveType(n ast.Vertex) {
switch nn := n.(type) {
case *ast.Nullable:
nsr.ResolveType(nn.Expr)
case *ast.Union:
for _, nnn := range nn.Types {
nsr.ResolveType(nnn)
}
case *ast.Name:
nsr.ResolveName(n, "")
case *ast.NameRelative:

View File

@ -540,6 +540,8 @@ func TestResolveFunctionName(t *testing.T) {
func TestResolveMethodName(t *testing.T) {
nameAB := &ast.Name{Parts: []ast.Vertex{&ast.NamePart{Value: []byte("A")}, &ast.NamePart{Value: []byte("B")}}}
nameBC := &ast.Name{Parts: []ast.Vertex{&ast.NamePart{Value: []byte("B")}, &ast.NamePart{Value: []byte("C")}}}
nameCD := &ast.Name{Parts: []ast.Vertex{&ast.NamePart{Value: []byte("C")}, &ast.NamePart{Value: []byte("D")}}}
nameDE := &ast.Name{Parts: []ast.Vertex{&ast.NamePart{Value: []byte("D")}, &ast.NamePart{Value: []byte("E")}}}
methodNode := &ast.StmtClassMethod{
Name: &ast.Identifier{Value: []byte("A")},
@ -548,6 +550,10 @@ func TestResolveMethodName(t *testing.T) {
Type: nameAB,
Var: &ast.ExprVariable{Name: &ast.Identifier{Value: []byte("foo")}},
},
&ast.Parameter{
Type: &ast.Union{Types: []ast.Vertex{nameCD, nameDE}},
Var: &ast.ExprVariable{Name: &ast.Identifier{Value: []byte("all")}},
},
},
ReturnType: &ast.Nullable{Expr: nameBC},
Stmt: &ast.StmtStmtList{
@ -558,6 +564,8 @@ func TestResolveMethodName(t *testing.T) {
expected := map[ast.Vertex]string{
nameAB: "A\\B",
nameBC: "B\\C",
nameCD: "C\\D",
nameDE: "D\\E",
}
nsResolver := nsresolver.NewNamespaceResolver()