Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Bad application of visibility rules on method parameter attributes? #273

Open
roji opened this issue Oct 24, 2015 · 10 comments
Open

Bad application of visibility rules on method parameter attributes? #273

roji opened this issue Oct 24, 2015 · 10 comments

Comments

@roji
Copy link
Member

roji commented Oct 24, 2015

I'm using Jetbrains Code Annotations in a library which also uses Code Contracts. I'm annotating parameters on some public methods with [NotNull] and [CanBeNull] attributes, but the CC rewriter complains about visibility:

Member 'JetBrains.Annotations.CanBeNullAttribute.#ctor' has less visibility than the enclosing method '...'

Now, it's true that I'm trying to apply an internal attribute (e.g. [NotNull]) to a public method. But why should this be a problem for CC? Shouldn't it be perfectly fine to have an internal attribute meant purely for internal consumption on a public method's parameters?

@SergeyTeplyakov
Copy link
Contributor

@roji interesting question:) Can you show simple workable example? I'm really surprised with this behavior...

@roji
Copy link
Member Author

roji commented Oct 25, 2015

Here's a minimal example:

public class Program
{
    static void Main(string[] args)
    {
    }

    public static void Foo([MyAttr] string s)
    {
        Contract.Requires(s.StartsWith("yo"));
    }
}

internal class MyAttr : Attribute {}

Trying to compile this with runtime contract checking fails with the following error:

1>c:\projects\Test2\Program.cs(19,13): error CC1038: Member 'Test2.MyAttr.#ctor' has less visibility than the enclosing method 'Test2.Program.Foo(System.String)'.

@SergeyTeplyakov
Copy link
Contributor

Thanks a lot! This sounds like a bug to me.

@SergeyTeplyakov
Copy link
Contributor

@roji I've created a PR with a fix for this bug. Would appreciate if you would be able to review it. (PR is #279).

@SergeyTeplyakov
Copy link
Contributor

New PR is #280.

@roji
Copy link
Member Author

roji commented Nov 2, 2015

Am trying to build CC to test this, but am getting the following when trying to build "Abstract Domains":

1>------ Build started: Project: Abstract Domains, Configuration: Debug Any CPU ------
1>  Reading assembly 'CodeAnalysis' from 'C:\projects\CodeContracts\Microsoft.Research\CodeAnalysis\bin\Debug\CodeAnalysis.dll' resulted in errors.
1>      Illegal characters in path.
1>ccrewrite : error : Rewrite aborted due to metadata errors. Check output window
1>  elapsed time: 2135.5723ms
1>C:\Program Files (x86)\Microsoft\Contracts\MsBuild\v14.0\Microsoft.CodeContracts.targets(265,5): error MSB3073: The command ""C:\Program Files (x86)\Microsoft\Contracts\Bin\ccrewrite.exe" "@Abstract Domainsccrewrite.rsp"" exited with code -1.
========== Build: 0 succeeded, 1 failed, 6 up-to-date, 0 skipped ==========

@fedotovalex
Copy link
Contributor

You must be building it in Visual Studio 2015 and you are hitting #186.

@SergeyTeplyakov
Copy link
Contributor

@roji Are you still hitting this issue? Is it related to VS2015 as @fedotovalex suggested or not?

@roji
Copy link
Member Author

roji commented Nov 4, 2015

I can confirm I'm on VS2015, I don't have an earlier version around to test on...

@SergeyTeplyakov
Copy link
Contributor

@roji Yeah, sorry for that, but currently the build will break on VS2015.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants