Commit Graph
16 Commits
Author SHA1 Message Date
upstream 3e462ad472 Upstream icsharpcode/ILSpy state of the touched files before 3c35e4cef6 2026-10-03 03:33:10 +02:00
dualfroz c61379b8b9 Fix #4016: Don't consume nullable flags for anonymous type arguments
Roslyn writes [Nullable] for an anonymous type as if the type was not
generic, so its type arguments have no flags. Taking one per argument
shifted every annotation after the anonymous type, which showed on the
cached lambda fields in <>c, and tripped the dummy-flag assert when the
shifted stream landed on a generic struct. [Dynamic] and
[TupleElementNames] do have entries for those arguments (checked against
what Roslyn emits), so only the nullable index skips them.
2026-10-03 02:29:11 +02:00
upstream 2dc58c945d Upstream icsharpcode/ILSpy state of the touched files before 23d0066f49 2026-10-03 02:29:11 +02:00
dualfroz e0a7ccf651 Expect the optimized dispatch labels from the legacy VB compiler too 2026-09-13 21:57:03 +02:00
dualfroz d2b048ebb7 Keep the Issue3659 expected output out of the format check 2026-09-13 21:01:36 +02:00
upstream b324f1f7aa Upstream icsharpcode/ILSpy state of the touched files before 352acfd456 2026-09-13 21:01:36 +02:00
dualfroz 14f32689d4 Replace the Issue3659 IL test with a VBPretty test 2026-09-13 18:32:51 +02:00
upstream 5088708223 Upstream icsharpcode/ILSpy state of the touched files before 39c6f5eada 2026-09-13 18:32:51 +02:00
dualfroz d5dfe13b26 Recognize a VB exception filter's type test
vbc builds an exception filter as a single non-short-circuiting
expression: `isinst`, then the user's `when` conditions, combined with
`and`. DetectCatchWhenConditionBlocks only knew the branch chain csc
emits, so the type test stayed inside the filter and the handler kept the
`object` variable it has in IL:

    catch (object obj) when ((obj is Exception) & (num2 != 0) & (num == 0))
    {
        ProjectData.SetProjectError((Exception)obj);

A catch type has to derive from Exception, so that does not compile.

The conjunction form is matched too now, lifting the test to the catch
type as the block form already does. The other conjuncts stop running for
a non-matching exception once the test moves, so the filter has to be
pure for this to be invisible; PropagateExceptionVariable then drops the
castclass in the handler:

    catch (Exception ex) when ((num2 != 0) & (num == 0))
    {
        ProjectData.SetProjectError(ex);

Closes #3659
2026-09-11 23:55:33 +02:00
upstream 8563d1b747 Upstream icsharpcode/ILSpy state of the touched files before 3d1d1be13b 2026-09-11 23:55:33 +02:00
dualfroz 594bb08fca Recognize a VB exception filter's type test
vbc builds an exception filter as a single non-short-circuiting
expression: `isinst`, then the user's `when` conditions, combined with
`and`. DetectCatchWhenConditionBlocks only knew the branch chain csc
emits, so the type test stayed inside the filter and the handler kept the
`object` variable it has in IL:

    catch (object obj) when ((obj is Exception) & (num2 != 0) & (num == 0))
    {
        ProjectData.SetProjectError((Exception)obj);

A catch type has to derive from Exception, so that does not compile.

The conjunction form is matched too now, lifting the test to the catch
type as the block form already does. The other conjuncts stop running for
a non-matching exception once the test moves, so the filter has to be
pure for this to be invisible; PropagateExceptionVariable then drops the
castclass in the handler:

    catch (Exception ex) when ((num2 != 0) & (num == 0))
    {
        ProjectData.SetProjectError(ex);

Closes #3659
2026-09-13 15:38:45 +02:00
upstream 297a659cc0 Upstream icsharpcode/ILSpy state of the touched files before 05718412c7 2026-09-11 23:55:33 +02:00
dualfroz b5ad0ac820 Recognize a VB exception filter's type test
vbc builds an exception filter as a single non-short-circuiting
expression: `isinst`, then the user's `when` conditions, combined with
`and`. DetectCatchWhenConditionBlocks only knew the branch chain csc
emits, so the type test stayed inside the filter and the handler kept the
`object` variable it has in IL:

    catch (object obj) when ((obj is Exception) & (num2 != 0) & (num == 0))
    {
        ProjectData.SetProjectError((Exception)obj);

A catch type has to derive from Exception, so that does not compile.

The conjunction form is matched too now, lifting the test to the catch
type as the block form already does. The other conjuncts stop running for
a non-matching exception once the test moves, so the filter has to be
pure for this to be invisible; PropagateExceptionVariable then drops the
castclass in the handler:

    catch (Exception ex) when ((num2 != 0) & (num == 0))
    {
        ProjectData.SetProjectError(ex);

Closes #3659
2026-09-15 19:16:29 +02:00
upstream aa0b6871d2 Upstream icsharpcode/ILSpy state of the touched files before d5ff770959 2026-09-11 23:55:33 +02:00
dualfroz 167098573c Keep a discarded method-group conversion out of the delegate cache
CachedDelegateInitializationWithField only fired when the instruction
after the caching `if` read the cache field exactly once. A discarded
conversion -- `_ = (Action<int>)M;` -- reads it zero times: Roslyn emits
the null check and the store, and nothing else. The transform bailed out,
so the `<>O` cache class and its `<0>__M` field survived into the output
under names no C# compiler will accept.

Zero usages is now handled: the `if` is replaced by the delegate
construction it guarded, which is what the source expressed, and the
caching disappears with the field. The rest of the method is checked for
loads of the same field first, since only then is this `if` the sole
initialization.

Closes #3965
2026-09-19 11:14:31 +02:00
upstream 80cf67e749 Upstream icsharpcode/ILSpy state of the touched files before 259e513829 2026-09-11 23:42:13 +02:00