Skip to content

Commit 92ee613

Browse files
committed
Add test for GetType call on ptr constrained to nullable
1 parent 807b896 commit 92ee613

File tree

5 files changed

+100
-0
lines changed

5 files changed

+100
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System;
5+
using System.Linq;
6+
using System.Collections.Generic;
7+
8+
class C<T>
9+
{
10+
public IEnumerable<T> Data { get; set; }
11+
12+
public C() { }
13+
14+
public bool Check()
15+
{
16+
return Data.ElementAt(0).GetType() == typeof(bool);
17+
}
18+
}
19+
20+
public class P
21+
{
22+
public static int Main()
23+
{
24+
C<bool?> c = new();
25+
26+
// Try a nullable with value
27+
c.Data = new List<bool?> { true };
28+
if(!c.Check())
29+
return 666;
30+
31+
// Try a nullable without value. Should throw NRE
32+
c.Data = new List<bool?> { new Nullable<bool>() };
33+
34+
bool thrown = false;
35+
try
36+
{
37+
c.Check();
38+
}
39+
catch(NullReferenceException)
40+
{
41+
thrown = true;
42+
}
43+
if(!thrown)
44+
return 667;
45+
return 100;
46+
}
47+
}
48+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
<CLRTestPriority>1</CLRTestPriority>
5+
</PropertyGroup>
6+
<PropertyGroup>
7+
<DebugType>Full</DebugType>
8+
<Optimize>False</Optimize>
9+
</PropertyGroup>
10+
<ItemGroup>
11+
<Compile Include="gettype.cs" />
12+
</ItemGroup>
13+
</Project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
<CLRTestPriority>1</CLRTestPriority>
5+
</PropertyGroup>
6+
<PropertyGroup>
7+
<DebugType>Full</DebugType>
8+
<Optimize>True</Optimize>
9+
</PropertyGroup>
10+
<ItemGroup>
11+
<Compile Include="gettype.cs" />
12+
</ItemGroup>
13+
</Project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
<CLRTestPriority>1</CLRTestPriority>
5+
</PropertyGroup>
6+
<PropertyGroup>
7+
<DebugType>None</DebugType>
8+
<Optimize>False</Optimize>
9+
</PropertyGroup>
10+
<ItemGroup>
11+
<Compile Include="gettype.cs" />
12+
</ItemGroup>
13+
</Project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
<CLRTestPriority>1</CLRTestPriority>
5+
</PropertyGroup>
6+
<PropertyGroup>
7+
<DebugType>None</DebugType>
8+
<Optimize>True</Optimize>
9+
</PropertyGroup>
10+
<ItemGroup>
11+
<Compile Include="gettype.cs" />
12+
</ItemGroup>
13+
</Project>

0 commit comments

Comments
 (0)