Skip to content

Commit d49a3b1

Browse files
authored
#143 - посещение идентификатора ищет среди переменных (#144)
* #143 - посещение идентификатора ищет среди переменных * #143 - Initialized переехало в VariableSymbol
1 parent 0134ba0 commit d49a3b1

File tree

4 files changed

+3
-7
lines changed

4 files changed

+3
-7
lines changed

src/Application/HydraScript.Application.StaticAnalysis/Visitors/SemanticChecker.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public Type Visit(ExpressionStatement visitable) =>
138138

139139
public Type Visit(IdentifierReference visitable)
140140
{
141-
var symbol = _symbolTables[visitable.Scope].FindSymbol<ISymbol>(visitable.Name);
141+
var symbol = _symbolTables[visitable.Scope].FindSymbol<VariableSymbol>(visitable.Name);
142142
if (symbol is { Initialized: false })
143143
throw new AccessBeforeInitialization(visitable);
144144
return symbol?.Type ?? throw new UnknownIdentifierReference(visitable);

src/Domain/HydraScript.Domain.IR/ISymbol.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@ public interface ISymbol
44
{
55
public string Id { get; }
66
public Type Type { get; }
7-
public bool Initialized { get; }
87
}

src/Domain/HydraScript.Domain.IR/Impl/Symbols/Symbol.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@ public abstract class Symbol(string id, Type type) : ISymbol
44
{
55
public virtual string Id { get; } = id;
66
public virtual Type Type { get; } = type;
7-
public virtual bool Initialized => true;
87
}

src/Domain/HydraScript.Domain.IR/Impl/Symbols/VariableSymbol.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@ public class VariableSymbol(
55
Type type,
66
bool readOnly = false) : Symbol(id, type)
77
{
8-
private bool _initialized = readOnly;
9-
108
public bool ReadOnly { get; } = readOnly;
11-
public override bool Initialized => _initialized;
9+
public bool Initialized { get; private set; } = readOnly;
1210

13-
public void Initialize() => _initialized = true;
11+
public void Initialize() => Initialized = true;
1412

1513
public override string ToString() =>
1614
$"{(ReadOnly ? "const " : "")}{Id}: {Type}";

0 commit comments

Comments
 (0)