38 Commits
Author SHA1 Message Date
Daniel Grunwald 3d10a04996 Avoid breaking LINQ query expressions with nullable reference types. 2026-08-30 12:07:45 +02:00
Christoph Wille fe9f6db3ee Emit C# 7.1 default literals where the context supplies the type
Shortening default(T) is the same problem as removing the redundant cast
around a lambda whose delegate type the context already fixes, so it uses
the same mechanism: ConvertTo makes the explicit type implicit when the
conversion is an identity conversion and the caller allows an implicit
one. The literal keeps the type it was shortened from, so any later
conversion to a different type - or any context that requires an explicit
type, such as an overload resolution recheck falling back to CastArguments
- can spell default(T) out again. That keeps the value intact where the
bare literal would change it, e.g. "object o = default(SomeStruct)", which
boxes a non-null struct while "default" would be null.

Because the shortened literal resolves to DefaultLiteralResolveResult,
CallBuilder's existing overload resolution recheck sees a real default
literal and rejects ambiguous calls on its own; no separate bookkeeping
about which arguments may stay untyped is needed. Only the contexts that
supply no target type at all restore the explicit form: an awaited
expression, and arguments of operator methods, which later become operator
or cast syntax rather than calls.

Assisted-by: Claude:claude-opus-5[1m]:Claude Code
2026-08-22 21:35:22 +02:00
Daniel Grunwald 30c6b70d9d Fix #3352: avoid using query expressions if there's indications that the lambda parameter types cannot be omitted.
I think this isn't reliable enough yet to actually omit parameter types for lambdas (it only protects against switching to the wrong overload; not against type inference failures); so for now it's only used in the query expression transform.
2026-08-17 21:51:37 +02:00
Siegfried Pammer 63900bb38c Align span conversions, betterness and inference with the C# 14 spec
Auditing against the first-class-span-types proposal turned up three
deviations, each now pinned by resolver unit tests whose expectations were
established by compiling probe programs with the C# 14 compiler.

Lower-bound type inference recursed into Span<T> targets as another
lower-bound inference, but Span<T> is invariant and the spec demands an
exact element inference there: M<T>(Span<T>, T) with (Span<string>, object)
must fail inference (CS0411), not unify to T=object.

Better-conversion-target compared ReadOnlySpan element types where the spec
compares the span types, admitting numeric and user-defined element
conversions the span types do not share: overloads taking ReadOnlySpan<int>
and ReadOnlySpan<long> are ambiguous (CS0121), not resolvable. The general
mutual-convertibility rule already implements the spec's span-type test, so
the element-level block is simply removed; the ReadOnlySpan-over-Span
identity rule stays, since it deliberately inverts that general rule.

The explicit span conversion did not exist at all, and with it the rule that
user-defined conversions are not considered between span-convertible types.
The visible consequence: string[] to Span<object> classified as an implicit
user-defined conversion via op_Implicit(object[]) plus array covariance,
where the compiler reports CS0266 - only the explicit span conversion
exists. Span conversions are also no longer considered for extension
receivers during method group conversion (CS0123), while invocations keep
them.

Part of #829.

Assisted-by: Claude:claude-fable-5:Claude Code
2026-08-15 18:42:53 +02:00
Daniel Grunwald a0b30a6902 Merge pull request #4006 from icsharpcode/refactor/usingscope-to-typesystem
Tidy up the resolve-result hierarchy and document the tuple-cast rule
2026-08-15 16:28:50 +02:00
Christoph Wille e475e26443 Make ThisResolveResult an ILVariableResolveResult of the this parameter
'this' and 'base' both read the 'this' parameter of the function being
decompiled, but their resolve result did not say so: consumers that key on
ILVariableResolveResult (local-reference output, highlighting, hover) could
not connect the keyword to the variable, and the qualified/unqualified
spellings of the same access carried differently shaped annotations.

The resolver has no ILFunction and thus no variable to put into a
ThisResolveResult, so it stops synthesizing one: LookInCurrentType looks
the name up against the (self-parameterized) current type, which grants
the same protected access, and the annotation of an unqualified field
access is built from the translated target instead. ResolveThisReference
and ResolveBaseReference had no callers left and are removed.

Assisted-by: Claude:claude-fable-5:Claude Code
2026-08-15 13:17:49 +02:00
Siegfried Pammer 471c3b1776 Move the remaining ResolveResult subclasses into the Semantics namespace
The resolve-result hierarchy was split between ICSharpCode.Decompiler.Semantics
and ICSharpCode.Decompiler.CSharp.Resolver, so consumers had to know which half
a given result came from and import both namespaces. All subclasses now live
next to their base class; MethodListWithDeclaringType follows the method group
it describes, and ILVariableResolveResult gets its own file instead of sitting
among the syntax-tree annotation helpers.

Assisted-by: Claude:claude-opus-5[1m]:Claude Code
2026-08-15 11:03:11 +02:00
Siegfried Pammer 69e2813298 Remove the unused ResolveResult.GetChildResults API
Nothing walked the resolve-result graph: the virtual method and its fourteen
overrides only ever called each other, with InvocationResolveResult's chained
base call as the sole call site in the tree.

Assisted-by: Claude:claude-opus-5[1m]:Claude Code
2026-08-15 11:03:10 +02:00
Siegfried Pammer 396b58031b Add support for C# 14 first-class span types in the type system. 2025-11-21 21:39:09 +01:00
Peter Crabtree e1e16b64f5 dev: Strip BOM mark from text files 2025-08-28 20:56:19 -04:00
Siegfried Pammer 79f7a188b0 Add support for C# 12 inline array expressions 2025-06-15 17:22:07 +02:00
Siegfried Pammer e6004e5f26 Handle ReferenceKind.RefReadOnly in a few more cases 2024-07-20 15:17:10 +02:00
Siegfried Pammer bde782e4f5 Fix #2806: Do not use implicitly typed out variables, if argument and parameter types do not match exactly. 2022-10-27 19:16:05 +02:00
Siegfried Pammer 3431881345 Fix #2307: potential NRE in IntroduceExtensionMethods 2021-02-21 20:23:33 +01:00
Siegfried Pammer 04f9603768 Fix #2140: ILSpy 6.2p1 no longer respects "use discards" setting 2020-09-03 09:06:47 +02:00
Daniel Grunwald 7f915ad035 Add OutVarResolveResult to overload resolution (not yet used by CallBuilder) 2020-09-02 21:39:28 +02:00
dotnet format 0d9f871a4f #2128: Reformat the whole code base. 2020-08-28 01:05:38 +02:00
Siegfried Pammer e211b01595 Fix CA1507:UseNameofInPlaceOfString, adjust formatting of some older source files copied from NRefactory. 2019-11-04 20:40:21 +01:00
Siegfried Pammer ddf4053a45 Fix merge conflict in Conversion.cs 2019-07-29 08:47:24 +02:00
Siegfried Pammer 79b56543e3 Merge branch 'master' of https://github.com/icsharpcode/ILSpy into throwExpression 2019-07-27 23:08:12 +02:00
Siegfried Pammer 9c1bf7fbdf Introduce ReferenceKind in IParameter and ByReferenceResolveResult. 2019-07-25 23:23:44 +02:00
Siegfried Pammer 1e64d37d15 Merge branch 'master' of https://github.com/icsharpcode/ILSpy into throwExpression 2019-05-09 17:19:17 +02:00
Daniel Grunwald 113acd48c1 Improve decompiler behavior is System.ValueTuple exists in multiple referenced assemblies.
This can happen if an application is compiled for .NET 4.6.2 and references
System.ValueTuple.dll; but ILSpy loads the latest mscorlib (e.g. .NET 4.7)
which also contains struct System.ValueTuple.
2019-02-24 19:24:21 +01:00
Daniel Grunwald 72d755037b Fix #1283: handle invalid metadata when decoding constants 2018-12-21 16:45:56 +01:00
Siegfried Pammer 0fc5c8b988 Add support for FormattableString patterns. 2018-08-01 19:47:34 +02:00
Daniel Grunwald 64547de4a0 foreach loops now use "var" if the element type is a tuple and can be inferred from the collection type.
Additionally, the tuple element names inferred from the collection type are now used when translating the foreach body.
2018-06-30 00:13:50 +02:00
Daniel Grunwald 97fc614db5 Remove unimplemented IMember.IsShadowing and IField.IsFixed. 2018-06-28 22:31:55 +02:00
Daniel Grunwald 0f8c310de2 Started work on new resolved TS implementation that directly uses SRM.
This is a work-in-progress; ILSpy is not functional with this commit.
The old code path still exists but is broken because some classes were modified for the new system.
The new system is still highly incomplete (types only have fields, but no methods).
2018-06-24 19:47:14 +02:00
Daniel Grunwald 58b0ddda9e Add ThrowExpressionConversion. 2018-06-02 09:16:02 +02:00
Daniel Grunwald 5cdd5ecdbc Use target typing for tuples, where possible. 2018-05-29 17:36:37 +02:00
Daniel Grunwald 926c7850ac Distinguish between unknown type and no type. 2018-05-28 17:38:53 +02:00
Daniel Grunwald 92b72c9570 Type system: add support for tuple conversions. 2018-05-14 22:33:10 +02:00
Daniel Grunwald da6b371dd3 Remove some dead code in the type system. 2018-03-09 22:47:37 +01:00
Siegfried Pammer 704eec86ae Add basic unit tests for ref returns, locals and conditional 2018-03-04 15:22:11 +01:00
Daniel Grunwald 1bcc255004 Remove a bunch of obsolete NRefactory code. 2017-09-04 20:49:45 +02:00
Siegfried Pammer 840ec04fde Namespace adjustments for Syntax classes 2016-11-26 12:06:58 +01:00
Christoph Wille 1ce8349dd9 Adjust namespaces 2016-11-26 11:12:53 +01:00
Siegfried Pammer 284ddfadf1 Phase 2: Merge ICSharpCode.NRefactory into ICSharpCode.Decompiler 2016-11-26 00:26:27 +01:00