From bfb8a4f7649d06617bfab52a5b4d9baffdc77d0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20M=C3=AD=C5=A1ek?= Date: Thu, 22 Aug 2024 16:00:39 +0200 Subject: [PATCH] body of declare() bound correctly + diagnostics test --- .../Semantics/Graph/BuilderVisitor.cs | 15 +++++++++++++-- .../Semantics/SemanticsBinder.cs | 13 ++++--------- .../Peachpie.DiagnosticTests/DiagnosticTest.cs | 8 ++++---- .../tests/5012_ignored_01.php | 4 ++-- 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/Peachpie.CodeAnalysis/Semantics/Graph/BuilderVisitor.cs b/src/Peachpie.CodeAnalysis/Semantics/Graph/BuilderVisitor.cs index ad5b512a7e..d5f9a76804 100644 --- a/src/Peachpie.CodeAnalysis/Semantics/Graph/BuilderVisitor.cs +++ b/src/Peachpie.CodeAnalysis/Semantics/Graph/BuilderVisitor.cs @@ -1,6 +1,7 @@ using Devsense.PHP.Syntax; using Devsense.PHP.Syntax.Ast; using Devsense.PHP.Text; +using Microsoft.CodeAnalysis; using Pchp.CodeAnalysis.Symbols; using System; using System.Collections.Generic; @@ -8,7 +9,6 @@ using System.Diagnostics; using System.Linq; using System.Text; -using System.Threading.Tasks; namespace Pchp.CodeAnalysis.Semantics.Graph { @@ -509,7 +509,18 @@ public override void VisitBlockStmt(BlockStmt x) public override void VisitDeclareStmt(DeclareStmt x) { - Add(x); // add to flow graph // will be ignored by semanti binder + // Add(x); // add to flow graph // will be ignored by semantic binder + + // declare() is ignored + _binder.Diagnostics.Add( + _binder.Routine, + Span.FromBounds(x.Span.Start, x.Statement.Span.Start).ToTextSpan(), + Errors.ErrorCode.WRN_NotYetImplementedIgnored, + $"declare()" + ); + + // bind the inner block + VisitElement(x.Statement); } public override void VisitGlobalCode(GlobalCode x) diff --git a/src/Peachpie.CodeAnalysis/Semantics/SemanticsBinder.cs b/src/Peachpie.CodeAnalysis/Semantics/SemanticsBinder.cs index fa55a43e9f..00d3d6eb88 100644 --- a/src/Peachpie.CodeAnalysis/Semantics/SemanticsBinder.cs +++ b/src/Peachpie.CodeAnalysis/Semantics/SemanticsBinder.cs @@ -360,16 +360,11 @@ BoundStatement BindStatementCore(AST.Statement stmt) if (stmt is AST.GlobalStmt glStmt) return BindGlobalStmt(glStmt); if (stmt is AST.StaticStmt staticStm) return BindStaticStmt(staticStm); if (stmt is AST.UnsetStmt unsetStm) return BindUnsetStmt(unsetStm); - if (stmt is AST.PHPDocStmt) return new BoundEmptyStatement(); - if (stmt is AST.DeclareStmt declareStm) - { - Diagnostics.Add(GetLocation(stmt), Errors.ErrorCode.WRN_NotYetImplementedIgnored, $"declare()"); - return new BoundDeclareStatement(); - } - + if (stmt is AST.PHPDocStmt) return BindEmptyStmt(stmt.Span); + // Diagnostics.Add(GetLocation(stmt), Errors.ErrorCode.ERR_NotYetImplemented, $"Statement of type '{stmt.GetType().Name}'"); - return new BoundEmptyStatement(stmt.Span.ToTextSpan()); + return BindEmptyStmt(stmt.Span); } BoundStatement BindEcho(AST.EchoStmt stmt, ImmutableArray args) @@ -408,7 +403,7 @@ BoundStatement BindGlobalStmt(AST.SimpleVarUse varuse) if (varuse is AST.DirectVarUse dvar && dvar.VarName.IsAutoGlobal) { // do not bind superglobals - return new BoundEmptyStatement(dvar.Span.ToTextSpan()); + return BindEmptyStmt(dvar.Span); } return new BoundGlobalVariableStatement( diff --git a/src/Tests/Peachpie.DiagnosticTests/DiagnosticTest.cs b/src/Tests/Peachpie.DiagnosticTests/DiagnosticTest.cs index 437b4d1960..d3ec9731de 100644 --- a/src/Tests/Peachpie.DiagnosticTests/DiagnosticTest.cs +++ b/src/Tests/Peachpie.DiagnosticTests/DiagnosticTest.cs @@ -113,17 +113,17 @@ private bool CheckDiagnostics(PhpSyntaxTree syntaxTree, Diagnostic[] actual, Mat while (iActual < actual.Length && iExpected < expected.Count) { // The comment is right after the expected diagnostic - int posActual = actual[iActual].Location.SourceSpan.End; - int posExpected = expected[iExpected].Index; + var posActual = actual[iActual].Location.SourceSpan; + var posExpected = new TextSpan(expected[iExpected].Index, expected[iExpected].Length); - if (posActual < posExpected) + if (posActual.End < posExpected.Start) { isCorrect = false; ReportUnexpectedDiagnostic(actual[iActual]); iActual++; } - else if (posActual > posExpected) + else if (posActual.Start > posExpected.End) { isCorrect = false; ReportMissingDiagnostic(syntaxTree, expected[iExpected]); diff --git a/src/Tests/Peachpie.DiagnosticTests/tests/5012_ignored_01.php b/src/Tests/Peachpie.DiagnosticTests/tests/5012_ignored_01.php index da98aee4c3..8194489250 100644 --- a/src/Tests/Peachpie.DiagnosticTests/tests/5012_ignored_01.php +++ b/src/Tests/Peachpie.DiagnosticTests/tests/5012_ignored_01.php @@ -1,7 +1,7 @@