Bug 33773 - Better codegen for lifted types in null operator
Summary: Better codegen for lifted types in null operator
Status: NEW
Alias: None
Product: Compilers
Classification: Mono
Component: C# (show other bugs)
Version: unspecified
Hardware: PC Mac OS
: --- enhancement
Target Milestone: ---
Assignee: Marek Safar
Depends on:
Reported: 2015-09-08 08:06 UTC by Marek Safar
Modified: 2015-09-08 08:06 UTC (History)
1 user (show)

See Also:
Is this bug a regression?: ---
Last known good build:


Description Marek Safar 2015-09-08 08:06:58 UTC
For most left+right expressions like binary, probe, null coalescing, etc. we could generate much better IL code.


class A
	public int P { get; set; }

class X
	public static void Main ()
		A a = null;
		var m = a?.P ?? 2;

`a?.P ?? 2` lifts int P to int? and then unwraps it with branch for 2. This all can be avoided and value `2` can be directly injected instead of empty nullable type being constructed and then checked for hasValue.

This is done for value types only and it can get tricky when we have receiver of multiple null operators (e.g. a?.P?.X).

Note You need to log in before you can comment on or make changes to this bug.