Skip to content

Commit

Permalink
body of declare() bound correctly + diagnostics test
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubmisek committed Aug 22, 2024
1 parent 2ee3d1b commit bfb8a4f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
15 changes: 13 additions & 2 deletions src/Peachpie.CodeAnalysis/Semantics/Graph/BuilderVisitor.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
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;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Pchp.CodeAnalysis.Semantics.Graph
{
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 4 additions & 9 deletions src/Peachpie.CodeAnalysis/Semantics/SemanticsBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<BoundArgument> args)
Expand Down Expand Up @@ -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(
Expand Down
8 changes: 4 additions & 4 deletions src/Tests/Peachpie.DiagnosticTests/DiagnosticTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
4 changes: 2 additions & 2 deletions src/Tests/Peachpie.DiagnosticTests/tests/5012_ignored_01.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

function foo(int $bar) {
declare(ticks = 1);/*!PHP5012!*/
declare(ticks = 1)/*!PHP5012!*/;

// Other diagnostics and type analysis must work within the block
declare(strict_types = 1)/*!PHP5012!*/ {
Expand All @@ -14,7 +14,7 @@ function foo(int $bar) {
}
}

declare(strict_types = 1);/*!PHP5012!*/
declare(strict_types = 1)/*!PHP5012!*/;

declare(strict_types = 1)/*!PHP5012!*/ {
if (false) {
Expand Down

0 comments on commit bfb8a4f

Please sign in to comment.