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

ILAsm: adds 'virtual' attribute to sealed default interface methods #13508

Closed
lambdageek opened this issue Mar 18, 2019 · 0 comments

Comments

@lambdageek
Copy link
Member

@lambdageek lambdageek commented Mar 18, 2019

Default interface methods is a feature of C# 8 that allows methods in interfaces to have bodies.

In C# methods in interfaces may be marked sealed in which case they are non-virtual and may not be overridden in derived interfaces or classes that implement the interface. In IL such methods are just non-virtual methods with a method body in an interface.

Our ilasm emits a warning and incorrectly applies a virtual attribute to such methods

Steps to Reproduce

  1. ilasm /dll dimsealed.il
  2. monodis dimsealed.dll
  3. Observe that I1.M1 is virtual

Current Behavior

virtual attribute added to method I1.M1

Expected Behavior

No virtual attribute.

On which platforms did you notice this

[x] macOS
[ ] Linux
[ ] Windows

Version Used:

Stacktrace

Mono JIT compiler version 6.1.0.471 (master/b20b86ff115 Thu Mar 14 11:28:36 PDT 2019)

Repro dimsealed.il:

.assembly extern mscorlib
{
  .ver 4:0:0:0
  .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
}
.assembly 'dimsealed'
{
  .custom instance void class [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::'.ctor'(int32) =  (01 00 08 00 00 00 00 00 ) // ........

  .custom instance void class [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::'.ctor'() =  (
		01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78   // ....T..WrapNonEx
		63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01       ) // ceptionThrows.

  .custom instance void class [mscorlib]System.Diagnostics.DebuggableAttribute::'.ctor'(valuetype [mscorlib]System.Diagnostics.DebuggableAttribute/DebuggingModes) =  (01 00 07 01 00 00 00 00 ) // ........

  .hash algorithm 0x00008004
  .ver  0:0:0:0
}
.module 'dimsealed'

  .class interface public auto ansi abstract I1
  {

    // method line 1
    .method public hidebysig 
           instance default void M1 ()  cil managed 
    {
        // Method begins at RVA 0x2050
	// Code size 13 (0xd)
	.maxstack 8
	IL_0000:  nop 
	IL_0001:  ldstr "M1"
	IL_0006:  call void class [mscorlib]System.Console::WriteLine(string)
	IL_000b:  nop 
	IL_000c:  ret 
    } // end of method I1::M1

  } // end of class I1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.