From 6855357aaa1d1f0ea02dd0e2d1f78881785152fe Mon Sep 17 00:00:00 2001 From: Tyler Christensen Date: Mon, 24 Apr 2023 12:26:00 -0600 Subject: [PATCH] php8.1: resolve intersection types in NamespaceResolver --- pkg/visitor/nsresolver/namespace_resolver.go | 4 ++++ pkg/visitor/nsresolver/namespace_resolver_test.go | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/pkg/visitor/nsresolver/namespace_resolver.go b/pkg/visitor/nsresolver/namespace_resolver.go index 865b2f4..ac3d847 100644 --- a/pkg/visitor/nsresolver/namespace_resolver.go +++ b/pkg/visitor/nsresolver/namespace_resolver.go @@ -283,6 +283,10 @@ func (nsr *NamespaceResolver) ResolveType(n ast.Vertex) { for _, nnn := range nn.Types { nsr.ResolveType(nnn) } + case *ast.Intersection: + for _, nnn := range nn.Types { + nsr.ResolveType(nnn) + } case *ast.Name: nsr.ResolveName(n, "") diff --git a/pkg/visitor/nsresolver/namespace_resolver_test.go b/pkg/visitor/nsresolver/namespace_resolver_test.go index 8220b56..7f62907 100644 --- a/pkg/visitor/nsresolver/namespace_resolver_test.go +++ b/pkg/visitor/nsresolver/namespace_resolver_test.go @@ -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")}}} 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")}}} + 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{ Name: &ast.Identifier{Value: []byte("A")}, @@ -554,6 +556,10 @@ func TestResolveMethodName(t *testing.T) { Type: &ast.Union{Types: []ast.Vertex{nameCD, nameDE}}, 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}, Stmt: &ast.StmtStmtList{ @@ -566,6 +572,8 @@ func TestResolveMethodName(t *testing.T) { nameBC: "B\\C", nameCD: "C\\D", nameDE: "D\\E", + nameEF: "E\\F", + nameFG: "F\\G", } nsResolver := nsresolver.NewNamespaceResolver()