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

ValidateInterfaceImplTable enforces bogus ordering rules #60454

Closed
MichalStrehovsky opened this issue Oct 15, 2021 · 3 comments · Fixed by #60541
Closed

ValidateInterfaceImplTable enforces bogus ordering rules #60454

MichalStrehovsky opened this issue Oct 15, 2021 · 3 comments · Fixed by #60541

Comments

@MichalStrehovsky
Copy link
Member

MichalStrehovsky commented Oct 15, 2021

Description

System.Reflection.Metadata metadata writer enforces weird rules around metadata validity for the InterfaceImpl table.

Reproduction Steps

It's not possible to generate a module with the metadata that corresponds to the following C# program:

interface I1
{
    void Method();
}

interface I2
{
    void Method();
}

class C1 : I1, I2
{
    public void Method() { }
}

class C2 : I2, I1
{
    public void Method() { }
}

Expected behavior

It's possible to generate interface list for I1, I2 and I2, I1.

Actual behavior

InvalidOperationException is thrown out of this code because it's impossible to have the interface list sorted both ways:

private void ValidateInterfaceImplTable()
{
if (_interfaceImplTable.Count == 0)
{
return;
}
InterfaceImplRow current, previous = _interfaceImplTable[0];
for (int i = 1; i < _interfaceImplTable.Count; i++, previous = current)
{
current = _interfaceImplTable[i];
if (current.Class > previous.Class)
{
continue;
}
if (previous.Class == current.Class && current.Interface > previous.Interface)
{
continue;
}
Throw.InvalidOperation_TableNotSorted(TableIndex.InterfaceImpl);
}
}

Interface index should not be looked at by this code.

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

@ghost
Copy link

ghost commented Oct 15, 2021

Tagging subscribers to this area: @buyaa-n
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

System.Reflection.Metadata metadata writer enforces made up rules around metadata validity for the InterfaceImpl table.

Reproduction Steps

It's not possible to generate a module with the metadata that corresponds to the following C# program:

interface I1
{
    void Method();
}

interface I2
{
    void Method();
}

class C1 : I1, I2
{
    public void Method() { }
}

class C2 : I2, I1
{
    public void Method() { }
}

Expected behavior

It's possible to generate interface list for I1, I2 and I2, I1.

Actual behavior

InvalidOperationException is thrown out of this code because it's impossible to have the interface list sorted both ways:

private void ValidateInterfaceImplTable()
{
if (_interfaceImplTable.Count == 0)
{
return;
}
InterfaceImplRow current, previous = _interfaceImplTable[0];
for (int i = 1; i < _interfaceImplTable.Count; i++, previous = current)
{
current = _interfaceImplTable[i];
if (current.Class > previous.Class)
{
continue;
}
if (previous.Class == current.Class && current.Interface > previous.Interface)
{
continue;
}
Throw.InvalidOperation_TableNotSorted(TableIndex.InterfaceImpl);
}
}

Interface index should not be looked at by this code.

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Author: MichalStrehovsky
Assignees: -
Labels:

area-System.Reflection.Metadata

Milestone: -

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged New issue has not been triaged by the area owner label Oct 15, 2021
MichalStrehovsky added a commit to MichalStrehovsky/iltrim that referenced this issue Oct 15, 2021
MichalStrehovsky added a commit to MichalStrehovsky/iltrim that referenced this issue Oct 15, 2021
@agocke
Copy link
Member

agocke commented Oct 15, 2021

This is the same as dotnet/roslyn#3905, but it was incorrectly thought to be a Roslyn bug, when it is in fact a SRM and spec bug -- I think ECMA's restriction here is too strict.

@MichalStrehovsky
Copy link
Member Author

Ah, didn't see ECMA calls for it. Such rule doesn't make sense - the interface ordering affects resolution rules (see II.12.2: - "Where there are multiple implementations for a given interface method due to differences in type
parameters, the declaration order of the interfaces on the class determines which method is invoked, as
well as the order in which the methods are declared"). The file format restriction would make it impossible to order things in a way the code intends.

Removing that line from the spec should go to the ECMA-335 addendums doc in this repo.

MichalStrehovsky added a commit to MichalStrehovsky/runtime that referenced this issue Oct 18, 2021
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Oct 18, 2021
@buyaa-n buyaa-n added this to the 7.0.0 milestone Oct 18, 2021
@buyaa-n buyaa-n removed the untriaged New issue has not been triaged by the area owner label Oct 18, 2021
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Nov 8, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Dec 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

3 participants