Skip to content

Commit

Permalink
Don't convert Nullable to Value for a non-type-inferred Return
Browse files Browse the repository at this point in the history
Fixes issue #188
  • Loading branch information
masonwheeler committed Mar 6, 2018
1 parent 52cc346 commit 569f3a1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Boo.Lang.Compiler/Steps/ProcessMethodBodies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2710,7 +2710,7 @@ override public void LeaveReturnStatement(ReturnStatement node)
AssertTypeCompatibility(node.Expression, returnType, expressionType);

//bind to nullable Value if needed
if (TypeSystemServices.IsNullable(expressionType) && !TypeSystemServices.IsNullable(returnType))
if (TypeSystemServices.IsNullable(expressionType) && !(TypeSystemServices.IsNullable(returnType) || TypeSystemServices.IsUnknown(returnType)))
{
// TODO: move to later steps or introduce an implicit conversion operator
var mre = new MemberReferenceExpression(node.Expression.LexicalInfo, node.Expression, "Value");
Expand Down
8 changes: 7 additions & 1 deletion tests/BooCompiler.Tests/GenericsTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,13 @@ public void nullable_6()
{
RunCompilerTestCase(@"nullable-6.boo");
}


[Test]
public void nullable_7()
{
RunCompilerTestCase(@"nullable-7.boo");
}

[Test]
public void override_1()
{
Expand Down
7 changes: 7 additions & 0 deletions tests/testcases/net2/generics/nullable-7.boo
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import System

def NullableTest():
return Default(Nullable[of int])

var value = NullableTest()
assert not value.HasValue

0 comments on commit 569f3a1

Please sign in to comment.