Skip to content

Commit

Permalink
invalid eval() reports all the diagnostics (not just the first one)
Browse files Browse the repository at this point in the history
solves #502
  • Loading branch information
jakubmisek committed Aug 27, 2019
1 parent 93c441e commit 256cd02
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/Peachpie.Library.Scripting/Context.Script.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,12 @@ public static Script Create(Context.ScriptOptions options, string code, PhpCompi
PhpParseOptions.Default,
options.Location.Path);


var diagnostics = tree.Diagnostics;
if (!HasErrors(diagnostics))
{
// TODO: collect required types from {tree}, remember as a script dependencies
// TODO: perform class autoload (now before compilation, and then always before invocation)

// unique in-memory assembly name
var name = builder.GetNewSubmissionName();

Expand Down Expand Up @@ -264,16 +266,13 @@ IEnumerable<MetadataReference> metadatareferences
/// <summary>
/// Initializes an invalid script that throws diagnostics upon invoking.
/// </summary>
/// <param name="diagnostics"></param>
/// <returns></returns>
private static Script CreateInvalid(IEnumerable<Diagnostic> diagnostics)
private static Script CreateInvalid(ImmutableArray<Diagnostic> diagnostics)
{
string errors = string.Join(Environment.NewLine, diagnostics.Select(d => $"{d.Severity} {d.Id}: {d.GetMessage()}"));

return new Script((ctx, locals, @this, self) =>
{
foreach (var d in diagnostics)
{
PhpException.Throw(PhpError.Error, d.GetMessage());
}
PhpException.Throw(PhpError.Error, string.Format("The script cannot be compiled due to following errors:\n{0}", errors));
//
return PhpValue.Void;
Expand Down

0 comments on commit 256cd02

Please sign in to comment.