Handle warnings, and add a warning if a function parameter has an unknown type

This commit is contained in:
2018-11-28 10:56:35 +01:00
parent 14e30d0855
commit 7ee230e20c
4 changed files with 44 additions and 14 deletions

View File

@@ -46,6 +46,7 @@ namespace Upsilon.Binder
foreach (var valueParameter in unboundFunctionStatement.Value.Parameters)
{
Scope.AssignToNearest(valueParameter.VariableSymbol);
_diagnostics.LogUnknownVariableType(valueParameter.VariableSymbol.Name, valueParameter.Span);
}
unboundFunctionStatement.Value.Block =
(BoundBlockStatement) BindBlockStatement(unboundFunctionStatement.Value.UnboundBlock);

View File

@@ -9,7 +9,8 @@ namespace Upsilon
public class Diagnostics
{
public SourceText ScriptString { get; }
public readonly List<DiagnosticsMessage> Messages = new List<DiagnosticsMessage>();
public readonly List<DiagnosticsMessage> Errors = new List<DiagnosticsMessage>();
public readonly List<DiagnosticsMessage> Warnings = new List<DiagnosticsMessage>();
public bool ThrowsOnError { get; }
public Diagnostics(SourceText scriptString, bool throwsOnError)
@@ -20,7 +21,10 @@ namespace Upsilon
public void Log(DiagnosticLevel level, string message, TextSpan location)
{
Messages.Add(new DiagnosticsMessage(this, level, message, location));
if (level == DiagnosticLevel.Error)
Errors.Add(new DiagnosticsMessage(this, level, message, location));
else if (level == DiagnosticLevel.Warning)
Warnings.Add(new DiagnosticsMessage(this, level, message, location));
}
public void LogError(string message, TextSpan location)
@@ -34,6 +38,11 @@ namespace Upsilon
Log(DiagnosticLevel.Error, message, location);
}
public void LogWarning(string message, TextSpan location)
{
Log(DiagnosticLevel.Warning, message, location);
}
public void LogBadCharacter(TextSpan location, SyntaxKind expectedToken, SyntaxKind currentKind)
{
LogError($"Invalid character found. Expected: '{expectedToken}', Got: '{currentKind}'", location);
@@ -87,18 +96,25 @@ namespace Upsilon
{
LogError($"Cannot index type '{expressionType}' with type '{indexType}'", span);
}
public void LogUnknownVariableType(string variableName, TextSpan span)
{
LogWarning(
$"Variable '{variableName}' has an unknown variable type, and as such errors won't be visible before evaluation.",
span);
}
}
public class DiagnosticsMessage
{
public Diagnostics Diagnostics { get; }
private readonly DiagnosticLevel _diagnosticLevel;
public DiagnosticLevel DiagnosticLevel { get; }
public string Message { get; }
public TextSpan Span { get; }
public DiagnosticsMessage(Diagnostics diagnostics, DiagnosticLevel diagnosticLevel, string message, TextSpan span)
{
_diagnosticLevel = diagnosticLevel;
DiagnosticLevel = diagnosticLevel;
Diagnostics = diagnostics;
Message = message;
Span = span;

View File

@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using Upsilon.BaseTypes;
using Upsilon.Binder;