File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed
ICSharpCode.Decompiler.Tests/TestCases/Correctness Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ static void Main()
3030 StringConcat ( ) ;
3131 LinqNullableMin ( ) ;
3232 LinqNullableMin ( 1 , 2 , 3 ) ;
33+ UnboxingToWrongType ( ) ;
3334 }
3435
3536 static void Print < T > ( T val )
@@ -110,5 +111,49 @@ static void LinqNullableMin(params int[] arr)
110111 Print ( string . Format ( "LinqNullableMin {0}:" , arr . Length ) ) ;
111112 Print ( arr . Min ( v => ( int ? ) v ) ) ;
112113 }
114+
115+ static void UnboxingToWrongType ( )
116+ {
117+ Console . WriteLine ( "UnboxingToWrongType:" ) ;
118+ object o = 3.50 ;
119+ try
120+ {
121+ Print ( ( long ) o ) ;
122+ }
123+ catch ( Exception ex )
124+ {
125+ Console . WriteLine ( ex . GetType ( ) . Name + ": " + ex . Message ) ;
126+ }
127+ try
128+ {
129+ Print ( o as long ? ) ;
130+ }
131+ catch ( Exception ex )
132+ {
133+ Console . WriteLine ( ex . GetType ( ) . Name + ": " + ex . Message ) ;
134+ }
135+ try
136+ {
137+ Print ( ( long ) ( o as long ? ) ) ;
138+ }
139+ catch ( Exception ex )
140+ {
141+ Console . WriteLine ( ex . GetType ( ) . Name + ": " + ex . Message ) ;
142+ }
143+ try
144+ {
145+ Print ( ( long ) ( o is long ? o : null ) ) ;
146+ }
147+ catch ( Exception ex )
148+ {
149+ Console . WriteLine ( ex . GetType ( ) . Name + ": " + ex . Message ) ;
150+ }
151+ #if CS90
152+ if ( o is not 0L )
153+ {
154+ Console . WriteLine ( "Not 0L" ) ;
155+ }
156+ #endif
157+ }
113158 }
114159}
You can’t perform that action at this time.
0 commit comments