File tree Expand file tree Collapse file tree 5 files changed +100
-0
lines changed
src/tests/JIT/Directed/nullabletypes Expand file tree Collapse file tree 5 files changed +100
-0
lines changed Original file line number Diff line number Diff line change
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
+
Original file line number Diff line number Diff line change
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 >
Original file line number Diff line number Diff line change
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 >
Original file line number Diff line number Diff line change
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 >
Original file line number Diff line number Diff line change
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 >
You can’t perform that action at this time.
0 commit comments