Skip to content

Commit

Permalink
Fixes #/issues/989
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertvanderHulst committed Mar 10, 2022
1 parent 6ba2f6c commit b74189f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
5 changes: 3 additions & 2 deletions Tests/Applications/C844/Prg/C844.prg
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// 844. Problem with iif() and NULL - /vo11 disabled
// error XS0029: Cannot implicitly convert type 'object' to 'string'
// 844. Problem with iif() and NULL - /vo10 disabled
// error XS0029: Cannot implicitly convert type 'object' to 'string'
#pragma options("vo10", off)
FUNCTION Start() AS VOID
LOCAL c AS STRING
c := iif(FALSE, "", NULL) // error XS0029
Expand Down
3 changes: 2 additions & 1 deletion Tests/Applications/C845/Prg/C845.prg
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// 844. Problem with iif() and NULL - /vo11 enabled
// 844. Problem with iif() and NULL - /vo10 enabled
// error XS0029: Cannot implicitly convert type 'object' to 'string'
#pragma options("vo10", on)
FUNCTION Start() AS VOID
LOCAL c AS STRING
c := iif(FALSE, "", NULL) // error XS0029
Expand Down
2 changes: 1 addition & 1 deletion Tests/xSharp Tests.viproj
Original file line number Diff line number Diff line change
Expand Up @@ -106884,7 +106884,7 @@ VO6=0
VO7=0
VO8=0
VO9=0
VO10=1
VO10=0
VO11=0
VO12=0
VO13=0
Expand Down
27 changes: 21 additions & 6 deletions XSharp/src/Compiler/XSharpCodeAnalysis/Binder/Binder_Operators.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1010,19 +1010,34 @@ private BoundExpression AdjustConstantType(BoundExpression expr, TypeSymbol type
public void VODetermineIIFTypes(ConditionalExpressionSyntax node, DiagnosticBag diagnostics,
ref BoundExpression trueExpr, ref BoundExpression falseExpr)
{
if (trueExpr is null || trueExpr.Type is null)
// a combination of null and a value type is not allowed
// in that case we replace the null with a default value.
var trueNull = trueExpr?.Type is null;
var falseNull = falseExpr?.Type is null;
if (trueNull && falseNull)
{
return;
}
else if (trueNull && !falseExpr.Type.IsReferenceType)
{
if (Compilation.Options.HasRuntime)
{
trueExpr = new BoundDefaultExpression(trueExpr.Syntax, Compilation.UsualType());
else
trueExpr = new BoundDefaultExpression(trueExpr.Syntax, Compilation.ObjectType);
trueNull = false;
}
}
if (falseExpr is null || falseExpr.Type is null)
else if (falseNull && !trueExpr.Type.IsReferenceType)
{
if (Compilation.Options.HasRuntime)
{
falseExpr = new BoundDefaultExpression(falseExpr.Syntax, Compilation.UsualType());
else
falseExpr = new BoundDefaultExpression(falseExpr.Syntax, Compilation.ObjectType);
falseNull = false;
}
}
if (trueNull || falseNull)
{
// this happens with the combination of a null and a reference type.
return;
}
// Determine underlying types. For literal numbers this may be Byte, Short, Int or Long
TypeSymbol trueType = VOGetType(trueExpr);
Expand Down

0 comments on commit b74189f

Please sign in to comment.