diff --git a/IDEHelper/Compiler/BfExprEvaluator.cpp b/IDEHelper/Compiler/BfExprEvaluator.cpp index 019d8901..f656aae5 100644 --- a/IDEHelper/Compiler/BfExprEvaluator.cpp +++ b/IDEHelper/Compiler/BfExprEvaluator.cpp @@ -18295,14 +18295,28 @@ BfTypedValue BfExprEvaluator::PerformUnaryOperation_TryOperator(const BfTypedVal result = mModule->GetDefaultTypedValue(methodMatcher.mSelfType); } - if ((methodMatcher.mBestMethodInstance) && (methodMatcher.mBestMethodInstance.mMethodInstance->mIsIntrinsic) && + if ((methodMatcher.mBestMethodInstance) && ((findOp == BfUnaryOp_Increment) || (findOp == BfUnaryOp_Decrement))) { - if (args[0].mTypedValue.IsAddr()) - mModule->mBfIRBuilder->CreateStore(result.mValue, args[0].mTypedValue.mValue); - else + if (methodMatcher.mBestMethodInstance.mMethodInstance->mIsIntrinsic) { - mModule->AssertErrorState(); + if (args[0].mTypedValue.IsAddr()) + mModule->mBfIRBuilder->CreateStore(result.mValue, args[0].mTypedValue.mValue); + else + { + mModule->AssertErrorState(); + } + } + else + { + if (!result.mType->IsValuelessType()) + { + if (targetVal.IsAddr()) + { + result = mModule->LoadValue(result); + mModule->mBfIRBuilder->CreateStore(result.mValue, targetVal.mValue); + } + } } } diff --git a/IDEHelper/Tests/src/Operators.bf b/IDEHelper/Tests/src/Operators.bf index cdacfcd7..e6f1ab93 100644 --- a/IDEHelper/Tests/src/Operators.bf +++ b/IDEHelper/Tests/src/Operators.bf @@ -23,6 +23,13 @@ namespace Tests res.mA = lhs.mA - rhs.mA; return res; } + + public static StructA operator++(StructA val) + { + StructA newVal; + newVal.mA = val.mA + 1; + return newVal; + } } struct StructB @@ -35,6 +42,11 @@ namespace Tests result.mA = sa.mA + sb.mB + 1000; return result; } + + public void operator++() mut + { + mB++; + } } struct StructC @@ -220,6 +232,20 @@ namespace Tests StructA sa4 = Op(sa0, sb0); Test.Assert(sa4.mA == 1012); + StructA sa6 = sa0++; + Test.Assert(sa0.mA == 2); + Test.Assert(sa6.mA == 1); + sa6 = ++sa0; + Test.Assert(sa0.mA == 3); + Test.Assert(sa6.mA == 3); + + StructB sb6 = sb0++; + Test.Assert(sb0.mB == 12); + Test.Assert(sb6.mB == 11); + sb6 = ++sb0; + Test.Assert(sb0.mB == 13); + Test.Assert(sb6.mB == 13); + float val = Op((int32)100, (int16)23); Test.Assert(val == 123);