Exemple #1
0
 internal static void ReportDefaultInterfaceImplementationModifiers(
     bool hasBody,
     DeclarationModifiers modifiers,
     DeclarationModifiers defaultInterfaceImplementationModifiers,
     Location errorLocation,
     BindingDiagnosticBag diagnostics)
 {
     if (!hasBody && (modifiers & defaultInterfaceImplementationModifiers) != 0)
     {
         LanguageVersion availableVersion = ((CSharpParseOptions)errorLocation.SourceTree.Options).LanguageVersion;
         LanguageVersion requiredVersion  = MessageID.IDS_DefaultInterfaceImplementation.RequiredVersion();
         if (availableVersion < requiredVersion)
         {
             DeclarationModifiers errorModifiers = modifiers & defaultInterfaceImplementationModifiers;
             var requiredVersionArgument         = new CSharpRequiredLanguageVersion(requiredVersion);
             var availableVersionArgument        = availableVersion.ToDisplayString();
             while (errorModifiers != DeclarationModifiers.None)
             {
                 DeclarationModifiers oneError = errorModifiers & ~(errorModifiers - 1);
                 Debug.Assert(oneError != DeclarationModifiers.None);
                 errorModifiers = errorModifiers & ~oneError;
                 diagnostics.Add(ErrorCode.ERR_InvalidModifierForLanguageVersion, errorLocation,
                                 ConvertSingleModifierToSyntaxText(oneError),
                                 availableVersionArgument,
                                 requiredVersionArgument);
             }
         }
     }
 }
Exemple #2
0
        internal static void ReportUnsupportedModifiersForLanguageVersion(DeclarationModifiers modifiers, DeclarationModifiers unsupportedModifiers, Location errorLocation, BindingDiagnosticBag diagnostics, LanguageVersion availableVersion, LanguageVersion requiredVersion)
        {
            DeclarationModifiers errorModifiers = modifiers & unsupportedModifiers;
            var requiredVersionArgument         = new CSharpRequiredLanguageVersion(requiredVersion);
            var availableVersionArgument        = availableVersion.ToDisplayString();

            while (errorModifiers != DeclarationModifiers.None)
            {
                DeclarationModifiers oneError = errorModifiers & ~(errorModifiers - 1);
                Debug.Assert(oneError != DeclarationModifiers.None);
                errorModifiers = errorModifiers & ~oneError;
                diagnostics.Add(ErrorCode.ERR_InvalidModifierForLanguageVersion, errorLocation,
                                ConvertSingleModifierToSyntaxText(oneError),
                                availableVersionArgument,
                                requiredVersionArgument);
            }
        }
Exemple #3
0
        public void SetProperty_MaxSupportedLangVersion(LanguageVersion?maxSupportedLangVersion)
        {
            using var environment = new TestEnvironment(typeof(CSharpParseOptionsChangingService));

            var hierarchy = environment.CreateHierarchy(
                "CSharpProject",
                "Bin",
                projectRefPath: null,
                projectCapabilities: "CSharp"
                );
            var storage = Assert.IsAssignableFrom <IVsBuildPropertyStorage>(hierarchy);

            Assert.True(
                ErrorHandler.Succeeded(
                    storage.SetPropertyValue(
                        "MaxSupportedLangVersion",
                        null,
                        (uint)_PersistStorageType.PST_PROJECT_FILE,
                        maxSupportedLangVersion?.ToDisplayString()
                        )
                    )
                );

            _ = CSharpHelpers.CreateCSharpProject(environment, "Test", hierarchy);

            var project = environment.Workspace.CurrentSolution.Projects.Single();

            var oldParseOptions = (CSharpParseOptions)project.ParseOptions;

            const LanguageVersion attemptedVersion = LanguageVersion.CSharp8;

            var canApply = environment.Workspace.CanApplyParseOptionChange(
                oldParseOptions,
                oldParseOptions.WithLanguageVersion(attemptedVersion),
                project
                );

            if (maxSupportedLangVersion.HasValue)
            {
                Assert.Equal(attemptedVersion <= maxSupportedLangVersion.Value, canApply);
            }
            else
            {
                Assert.True(canApply);
            }
        }