Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[X] Compiled Bindings to Array #15944

Merged
merged 1 commit into from
Jul 18, 2023
Merged

[X] Compiled Bindings to Array #15944

merged 1 commit into from
Jul 18, 2023

Conversation

StephaneDelcroix
Copy link
Contributor

Description of Change

emit ldelem opcodes for accessing arrays elements in compiled bindings

Issues Fixed

Fixes #10396

emit ldelem opcodes for accessing arrays elements in compiled bindings
@@ -719,7 +737,7 @@ static IEnumerable<Instruction> CompiledBindingGetSetter(TypeReference tSourceRe
setter.Body.InitLocals = true;

var il = setter.Body.GetILProcessor();
if (!properties.Any() || properties.Last().property.SetMethod == null)
if (!properties.Any() || properties.Last().property == null || properties.Last().property.SetMethod == null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could simplify this to something like:

Suggested change
if (!properties.Any() || properties.Last().property == null || properties.Last().property.SetMethod == null)
if (properties.Last() is ThePropertyType p && p.property == null || p.property.SetMethod == null)

Which could avoid calling Any() and Last() as many times.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you mean LastOrDefault ?

else
throw new BuildException(BindingIndexerParse, lineInfo, null, indexArg, property.Name);
{
var indexType = property.GetMethod.Parameters[0].ParameterType.ResolveGenericParameters(propDeclTypeRef);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be terrible to do in practice... But can you make C# indexers with multiple parameters?

public string this[string key1, string key2]
{
    get => someTupleDictionary[(key1, key2)]; 
    set => someTupleDictionary[(key1, key2)] = value;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, this PR is about arrays, not indexers, but yeah, it doesn't cover multidimensional arrays 🙉🙉🙉

src/Controls/src/Core/TypedBinding.cs Show resolved Hide resolved
src/Controls/src/Core/TypedBinding.cs Show resolved Hide resolved
@jsuarezruiz jsuarezruiz added the area-xaml XAML, CSS, Triggers, Behaviors label Jul 3, 2023
@rmarinho rmarinho merged commit bcffd04 into main Jul 18, 2023
@rmarinho rmarinho deleted the fix-10396 branch July 18, 2023 16:52
@github-actions github-actions bot locked and limited conversation to collaborators Dec 8, 2023
@samhouts samhouts added the fixed-in-8.0.0-preview.7.8842 Look for this fix in 8.0.0-preview.7.8842! label Aug 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-xaml XAML, CSS, Triggers, Behaviors fixed-in-8.0.0-preview.7.8842 Look for this fix in 8.0.0-preview.7.8842!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

XamlC compiler null-refs when encountering a binding to an array access
6 participants