Skip to content

Commit 569f3a1

Browse files
committed
Don't convert Nullable to Value for a non-type-inferred Return
Fixes issue #188
1 parent 52cc346 commit 569f3a1

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

src/Boo.Lang.Compiler/Steps/ProcessMethodBodies.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2710,7 +2710,7 @@ override public void LeaveReturnStatement(ReturnStatement node)
27102710
AssertTypeCompatibility(node.Expression, returnType, expressionType);
27112711

27122712
//bind to nullable Value if needed
2713-
if (TypeSystemServices.IsNullable(expressionType) && !TypeSystemServices.IsNullable(returnType))
2713+
if (TypeSystemServices.IsNullable(expressionType) && !(TypeSystemServices.IsNullable(returnType) || TypeSystemServices.IsUnknown(returnType)))
27142714
{
27152715
// TODO: move to later steps or introduce an implicit conversion operator
27162716
var mre = new MemberReferenceExpression(node.Expression.LexicalInfo, node.Expression, "Value");

tests/BooCompiler.Tests/GenericsTestFixture.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,13 @@ public void nullable_6()
614614
{
615615
RunCompilerTestCase(@"nullable-6.boo");
616616
}
617-
617+
618+
[Test]
619+
public void nullable_7()
620+
{
621+
RunCompilerTestCase(@"nullable-7.boo");
622+
}
623+
618624
[Test]
619625
public void override_1()
620626
{
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import System
2+
3+
def NullableTest():
4+
return Default(Nullable[of int])
5+
6+
var value = NullableTest()
7+
assert not value.HasValue

0 commit comments

Comments
 (0)