diff --git a/src/Boo.Lang.Compiler/Steps/ProcessMethodBodies.cs b/src/Boo.Lang.Compiler/Steps/ProcessMethodBodies.cs index 217e6b620..ab97cd93c 100755 --- a/src/Boo.Lang.Compiler/Steps/ProcessMethodBodies.cs +++ b/src/Boo.Lang.Compiler/Steps/ProcessMethodBodies.cs @@ -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"); diff --git a/tests/BooCompiler.Tests/GenericsTestFixture.cs b/tests/BooCompiler.Tests/GenericsTestFixture.cs index c714de43f..0561738c1 100644 --- a/tests/BooCompiler.Tests/GenericsTestFixture.cs +++ b/tests/BooCompiler.Tests/GenericsTestFixture.cs @@ -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() { diff --git a/tests/testcases/net2/generics/nullable-7.boo b/tests/testcases/net2/generics/nullable-7.boo new file mode 100644 index 000000000..db8b6f988 --- /dev/null +++ b/tests/testcases/net2/generics/nullable-7.boo @@ -0,0 +1,7 @@ +import System + +def NullableTest(): + return Default(Nullable[of int]) + +var value = NullableTest() +assert not value.HasValue \ No newline at end of file