php8.1: resolve intersection types in NamespaceResolver

This commit is contained in:
Tyler Christensen 2023-04-24 12:26:00 -06:00 committed by Laytan Laats
parent 3c45afd848
commit 6855357aaa
2 changed files with 12 additions and 0 deletions

View File

@ -283,6 +283,10 @@ func (nsr *NamespaceResolver) ResolveType(n ast.Vertex) {
for _, nnn := range nn.Types { for _, nnn := range nn.Types {
nsr.ResolveType(nnn) nsr.ResolveType(nnn)
} }
case *ast.Intersection:
for _, nnn := range nn.Types {
nsr.ResolveType(nnn)
}
case *ast.Name: case *ast.Name:
nsr.ResolveName(n, "") nsr.ResolveName(n, "")

View File

@ -542,6 +542,8 @@ func TestResolveMethodName(t *testing.T) {
nameBC := &ast.Name{Parts: []ast.Vertex{&ast.NamePart{Value: []byte("B")}, &ast.NamePart{Value: []byte("C")}}} 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")}}} 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")}}} nameDE := &ast.Name{Parts: []ast.Vertex{&ast.NamePart{Value: []byte("D")}, &ast.NamePart{Value: []byte("E")}}}
nameEF := &ast.Name{Parts: []ast.Vertex{&ast.NamePart{Value: []byte("E")}, &ast.NamePart{Value: []byte("F")}}}
nameFG := &ast.Name{Parts: []ast.Vertex{&ast.NamePart{Value: []byte("F")}, &ast.NamePart{Value: []byte("G")}}}
methodNode := &ast.StmtClassMethod{ methodNode := &ast.StmtClassMethod{
Name: &ast.Identifier{Value: []byte("A")}, Name: &ast.Identifier{Value: []byte("A")},
@ -554,6 +556,10 @@ func TestResolveMethodName(t *testing.T) {
Type: &ast.Union{Types: []ast.Vertex{nameCD, nameDE}}, Type: &ast.Union{Types: []ast.Vertex{nameCD, nameDE}},
Var: &ast.ExprVariable{Name: &ast.Identifier{Value: []byte("all")}}, Var: &ast.ExprVariable{Name: &ast.Identifier{Value: []byte("all")}},
}, },
&ast.Parameter{
Type: &ast.Intersection{Types: []ast.Vertex{nameEF, nameFG}},
Var: &ast.ExprVariable{Name: &ast.Identifier{Value: []byte("any")}},
},
}, },
ReturnType: &ast.Nullable{Expr: nameBC}, ReturnType: &ast.Nullable{Expr: nameBC},
Stmt: &ast.StmtStmtList{ Stmt: &ast.StmtStmtList{
@ -566,6 +572,8 @@ func TestResolveMethodName(t *testing.T) {
nameBC: "B\\C", nameBC: "B\\C",
nameCD: "C\\D", nameCD: "C\\D",
nameDE: "D\\E", nameDE: "D\\E",
nameEF: "E\\F",
nameFG: "F\\G",
} }
nsResolver := nsresolver.NewNamespaceResolver() nsResolver := nsresolver.NewNamespaceResolver()