This repository was archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Fix two array-related bugs in Microsoft.CSharp #17810
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Xunit; | ||
|
||
namespace Microsoft.CSharp.RuntimeBinder.Tests | ||
{ | ||
public class ArrayHandling | ||
{ | ||
[Fact] | ||
public void SingleRankNonSZArray() | ||
{ | ||
dynamic d = Array.CreateInstance(typeof(int), new[] { 8 }, new[] { -2 }); | ||
d.SetValue(32, 3); | ||
d.SetValue(28, -1); | ||
Assert.Equal(32, d.GetValue(3)); | ||
Assert.Equal(28, d.GetValue(-1)); | ||
} | ||
|
||
[Fact] | ||
public void SingleRankNonSZArrayIndexed() | ||
{ | ||
dynamic d = Array.CreateInstance(typeof(int), new[] { 8 }, new[] { -2 }); | ||
d[3] = 32; | ||
d[-1] = 28; | ||
Assert.Equal(32, d[3]); | ||
Assert.Equal(28, d[-1]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This case is an interesting side-effect in that it's not possible to do compile the static equivalent, and yet the usage here seems reasonable and so not worth the explicit prohibition it would require to refuse it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, one can currently do the equivalent with non-zero-based arrays of higher ranks, so prohibiting it here would have to either be a breaking change to that or else inconsistent with it. |
||
} | ||
|
||
[Fact] | ||
public void ArrayTypeNames() | ||
{ | ||
dynamic d = Array.CreateInstance(typeof(int), new[] { 8 }, new[] { -2 }); | ||
RuntimeBinderException ex = Assert.Throws<RuntimeBinderException>(() => { string s = d; }); | ||
Assert.Contains("int[*]", ex.Message); | ||
|
||
d = new int[3]; | ||
ex = Assert.Throws<RuntimeBinderException>(() => { string s = d; }); | ||
Assert.Contains("int[]", ex.Message); | ||
|
||
d = new int[3, 2, 1]; | ||
ex = Assert.Throws<RuntimeBinderException>(() => { string s = d; }); | ||
Assert.Contains("int[,,]", ex.Message); | ||
|
||
d = Array.CreateInstance(typeof(int), new[] { 3, 2, 1 }, new[] { -2, 2, -0 }); | ||
ex = Assert.Throws<RuntimeBinderException>(() => { string s = d; }); | ||
Assert.Contains("int[,,]", ex.Message); | ||
|
||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does anyone know what this
CSEE
constant refers to?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm guessing the C# expression evaluator. Like below. @VSadov to confirm.
https://github.com/dotnet/corefx/blob/master/src/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/Types/AggregateType.cs#L22
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case, we need to find out why would the result be different?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case the CSEE behaviour is what I'd think would be correct for any case (except that it doesn't handle single-ranked non-SZ arrays but the assembly as a whole had no concept of SZ/non-SZ distinction before this PR).
In other cases I'm not sure what to do when I come across it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It appears to be pieces that supports Expression Evaluator that is used at debug time. They make no sense in the dynamic binder code.
I guess they were just ported together with the rest of the code. Perhaps the initial pass used some automated translator and it picked up everything, or it was expected that there would be a need for a special binder - specifically for EE to call into, but that need never materialized...
Anyways, I am not aware of any CSEE flavor of the runtime binder.
The "CSEE" seems just dead code and can/should be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll do that soon, so.