Skip to content

Commit

Permalink
Fix null-safety issues
Browse files Browse the repository at this point in the history
  • Loading branch information
SomeRanDev committed Dec 1, 2023
1 parent 8f7d1e1 commit e1864a0
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/reflaxe/ReflectCompiler.hx
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,9 @@ class ReflectCompiler {
if(compiler.options.normalizeEIE) {
final eiec = new EverythingIsExprSanitizer(data.expr, compiler);
data.setExpr(eiec.convertedExpr());
data.setVariableUsageCount(eiec.variableUsageCount);
if(eiec.variableUsageCount != null) {
data.setVariableUsageCount(eiec.variableUsageCount);
}
}
if(compiler.options.processAvoidTemporaries) {
final tvr = new TemporaryVarRemover(data.expr, data.getOrFindVariableUsageCount());
Expand Down
4 changes: 2 additions & 2 deletions src/reflaxe/compiler/EverythingIsExprSanitizer.hx
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,12 @@ class EverythingIsExprSanitizer {
/**
Search through parents to find valid `variableUsageCount`.
**/
function getVariableUsageCount() {
function getVariableUsageCount(): Map<Int, Int> {
var p = this;
while(p.parent != null) {
p = p.parent;
}
return p.variableUsageCount;
return p.variableUsageCount.trustMe(); // The top-most should always exist.
}

public function convertedExpr(): TypedExpr {
Expand Down
2 changes: 1 addition & 1 deletion src/reflaxe/compiler/TemporaryVarRemover.hx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class TemporaryVarRemover {
**/
function getVariableUsageCount(variableId: Int): Int {
return if(varUsageCount != null && varUsageCount.exists(variableId)) {
varUsageCount.get(variableId);
varUsageCount.get(variableId) ?? 0;
} else {
0;
}
Expand Down
4 changes: 4 additions & 0 deletions src/reflaxe/data/ClassFuncData.hx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ class ClassFuncData {
If it has not been calculated yet, it is calculated here.
**/
public function getOrFindVariableUsageCount(): Map<Int, Int> {
if(expr == null) {
return [];
}

final map: Map<Int, Int> = [];
function count(e: TypedExpr) {
switch(e.expr) {
Expand Down

0 comments on commit e1864a0

Please sign in to comment.