From f869bb3978df44cc29cdfc6717044f2f248a3821 Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Sat, 11 Apr 2020 07:32:40 -0700 Subject: [PATCH] Fixed some struct-init-detection code --- IDEHelper/Compiler/BfExprEvaluator.cpp | 2 +- IDEHelper/Tests/src/StructInit.bf | 60 ++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 IDEHelper/Tests/src/StructInit.bf diff --git a/IDEHelper/Compiler/BfExprEvaluator.cpp b/IDEHelper/Compiler/BfExprEvaluator.cpp index 30bcad66..fb0e4f6d 100644 --- a/IDEHelper/Compiler/BfExprEvaluator.cpp +++ b/IDEHelper/Compiler/BfExprEvaluator.cpp @@ -3586,7 +3586,7 @@ BfTypedValue BfExprEvaluator::LookupField(BfAstNode* targetSrc, BfTypedValue tar } } - int fieldIdx = -1; + int fieldIdx = mResultLocalVarField - 1; if (fieldIdx == -1) { mResultLocalVarField = minMergedDataIdx + 1; diff --git a/IDEHelper/Tests/src/StructInit.bf b/IDEHelper/Tests/src/StructInit.bf new file mode 100644 index 00000000..636908e4 --- /dev/null +++ b/IDEHelper/Tests/src/StructInit.bf @@ -0,0 +1,60 @@ +namespace Tests +{ + class StructInit + { + struct StructA + { + public int mA0; + } + + struct StructB + { + public int mB0; + public int mB1; + } + + struct StructC + { + public StructA mSA; + public StructB mSB; + + public this() + { + mSA.mA0 = 1; + mSB.mB0 = 2; + mSB.mB1 = 3; + } + } + + struct StructD + { + public StructC mSC; + public int mD0; + + public this() + { + mSC.mSA.mA0 = 1; + mSC.mSB.mB0 = 2; + mSC.mSB.mB1 = 3; + mD0 = 4; + } + } + + struct StructE + { + public StructD mSD; + public int[3] mE0; + + public this() + { + mSD.mSC.mSA.mA0 = 1; + mSD.mSC.mSB.mB0 = 2; + mSD.mSC.mSB.mB1 = 3; + mSD.mD0 = 4; + mE0[0] = 5; + mE0[1] = 6; + mE0[2] = 7; + } + } + } +}