File tree Expand file tree Collapse file tree 5 files changed +10
-16
lines changed
Application/HydraScript.Application.StaticAnalysis/Visitors
HydraScript.Domain.FrontEnd/Parser/Impl/Ast/Nodes/Declarations/AfterTypesAreLoaded
HydraScript.Domain.IR/Impl/Symbols
tests/HydraScript.UnitTests/Application Expand file tree Collapse file tree 5 files changed +10
-16
lines changed Original file line number Diff line number Diff line change @@ -76,6 +76,7 @@ public VisitUnit Visit(FunctionDeclaration visitable)
7676 {
7777 var returnAnalyzerResult = visitable . Accept ( _returnAnalyzer ) ;
7878 visitable . ReturnStatements = returnAnalyzerResult . ReturnStatements ;
79+ visitable . AllCodePathsEndedWithReturn = returnAnalyzerResult . CodePathEndedWithReturn ;
7980
8081 var parentTable = _symbolTables [ visitable . Parent . Scope ] ;
8182 var indexOfFirstDefaultArgument = visitable . Arguments . AsValueEnumerable ( )
@@ -94,8 +95,7 @@ public VisitUnit Visit(FunctionDeclaration visitable)
9495 visitable . Name ,
9596 parameters ,
9697 visitable . ReturnTypeValue . Accept ( _typeBuilder ) ,
97- visitable . IsEmpty ,
98- returnAnalyzerResult . CodePathEndedWithReturn ) ;
98+ visitable . IsEmpty ) ;
9999 if ( functionSymbolId . Equals ( parentTable . FindSymbol ( functionSymbolId ) ? . Id ) )
100100 throw new OverloadAlreadyExists ( visitable . Name , functionSymbolId ) ;
101101
Original file line number Diff line number Diff line change @@ -510,7 +510,7 @@ public Type Visit(FunctionDeclaration visitable)
510510 symbol . DefineReturnType ( returnTypes . Single ( ) ) ;
511511
512512 Type @void = "void" ;
513- if ( ! symbol . Type . Equals ( @void ) && ! symbol . AllCodePathsEndedWithReturn )
513+ if ( ! symbol . Type . Equals ( @void ) && ! visitable . AllCodePathsEndedWithReturn )
514514 throw new FunctionWithoutReturnStatement ( visitable . Segment ) ;
515515
516516 if ( symbol . Type is NullType )
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ public partial class FunctionDeclaration : AfterTypesAreLoadedDeclaration
2020
2121 public IReadOnlyList < ReturnStatement > ReturnStatements { get ; set ; } = [ ] ;
2222 public bool HasReturnStatement => ReturnStatements . Count > 0 ;
23+ public bool AllCodePathsEndedWithReturn { get ; set ; }
2324
2425 public string ComputedFunctionAddress { get ; set ; } = string . Empty ;
2526
Original file line number Diff line number Diff line change @@ -8,8 +8,7 @@ public class FunctionSymbol(
88 string name ,
99 IReadOnlyList < ISymbol > parameters ,
1010 Type type ,
11- bool isEmpty ,
12- bool allCodePathsEndedWithReturn ) : Symbol ( name , type )
11+ bool isEmpty ) : Symbol ( name , type )
1312{
1413 private Type _returnType = type ;
1514 /// <summary>Тип возврата функции</summary>
@@ -22,7 +21,6 @@ public class FunctionSymbol(
2221
2322 public IReadOnlyList < ISymbol > Parameters { get ; } = parameters ;
2423 public bool IsEmpty { get ; } = isEmpty ;
25- public bool AllCodePathsEndedWithReturn { get ; } = allCodePathsEndedWithReturn ;
2624
2725 public void DefineReturnType ( Type returnType ) =>
2826 _returnType = returnType ;
Original file line number Diff line number Diff line change @@ -21,8 +21,7 @@ public void StorageIsEmptyAfterFlushTest()
2121 name : FunctionName ,
2222 parameters : [ ] ,
2323 "undefined" ,
24- isEmpty : false ,
25- allCodePathsEndedWithReturn : false ) ;
24+ isEmpty : false ) ;
2625
2726 var decl = new FunctionDeclaration (
2827 name : new IdentifierReference ( FunctionName ) ,
@@ -71,31 +70,27 @@ public void StorageIsCorrectOrderTest()
7170 name : "key2" ,
7271 parameters : [ ] ,
7372 "undefined" ,
74- isEmpty : false ,
75- allCodePathsEndedWithReturn : false ) ;
73+ isEmpty : false ) ;
7674
7775 storage . Save ( new FunctionSymbol (
7876 name : "key1" ,
7977 parameters : [ ] ,
8078 "undefined" ,
81- isEmpty : false ,
82- allCodePathsEndedWithReturn : false ) , declaration : declarations [ 0 ] ) ;
79+ isEmpty : false ) , declaration : declarations [ 0 ] ) ;
8380
8481 storage . Save ( removable , declaration : declarations [ 1 ] ) ;
8582
8683 storage . Save ( new FunctionSymbol (
8784 name : "key3" ,
8885 parameters : [ ] ,
8986 "undefined" ,
90- isEmpty : false ,
91- allCodePathsEndedWithReturn : false ) , declaration : declarations [ 2 ] ) ;
87+ isEmpty : false ) , declaration : declarations [ 2 ] ) ;
9288
9389 storage . Save ( new FunctionSymbol (
9490 name : "key4" ,
9591 parameters : [ ] ,
9692 "undefined" ,
97- isEmpty : false ,
98- allCodePathsEndedWithReturn : false ) , declaration : declarations [ 3 ] ) ;
93+ isEmpty : false ) , declaration : declarations [ 3 ] ) ;
9994
10095 storage . RemoveIfPresent ( removable ) ;
10196
You can’t perform that action at this time.
0 commit comments