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

Interface-Method: IsSealed does not work as expected #73441

Closed
bernd5 opened this issue May 12, 2024 · 5 comments
Closed

Interface-Method: IsSealed does not work as expected #73441

bernd5 opened this issue May 12, 2024 · 5 comments
Labels
Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead

Comments

@bernd5
Copy link
Contributor

bernd5 commented May 12, 2024

Version Used:

Steps to Reproduce:

Execute:

using System;
using System.Linq;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;

using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;


var tree = ParseSyntaxTree("""
using System;
						   
interface IFoo
{
    sealed void SealedMethod()
    {
        Console.WriteLine("IFoo.SealedMethod");
    }    
}					  
""");

var refApis = AppDomain.CurrentDomain.GetAssemblies()
    .Where(a => !a.IsDynamic)
    .Select(a => MetadataReference.CreateFromFile(a.Location));

var compilation = CSharpCompilation.Create("something", new[] { tree }, refApis);
compilation = compilation.WithOptions(compilation.Options.WithOutputKind(OutputKind.DynamicallyLinkedLibrary));
var method = compilation.SyntaxTrees.First().GetRoot().DescendantNodes().OfType<MethodDeclarationSyntax>().Single();

var symbol = compilation.GetSemanticModel(method.SyntaxTree).GetDeclaredSymbol(method);
Console.WriteLine(symbol.IsSealed); //<-- returns false

Expected Behavior:
Expected output: True

Actual Behavior:
Prints: False

Is there any API to get the "correct" IsSealed value?
The "Sealed" value seems to be encoded with the newslot flag - but that detail should not be part of the public API, or?

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels May 12, 2024
@CyrusNajmabadi
Copy link
Member

Interesting. This might be a bug. Compiler team would have to check. In the meantime, you can check for this syntactically on the method decl node you searched for.

@jaredpar
Copy link
Member

@333fred can you confirm whether or not this behavior is intended?

@333fred
Copy link
Member

333fred commented May 20, 2024

@AlekseyTs would be better to comment here.

@333fred
Copy link
Member

333fred commented May 20, 2024

However, I'm guessing this is intentional, as we don't emit final into the IL here.

@AlekseyTs
Copy link
Contributor

This is by design. For interface members, sealed modifier means not-virtual.

@jaredpar jaredpar closed this as not planned Won't fix, can't repro, duplicate, stale May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

No branches or pull requests

5 participants