예제 #1
0
        public IErrorReporter ErrorInOutVarianceProperties()
        {
            NameResolver resolver = null;

            foreach (var mutability in Options.AllMutabilityModes)
            {
                var env = Language.Environment.Create(new Options()
                {
                    DiscardingAnyExpressionDuringTests = true
                }
                                                      .SetMutability(mutability));
                var root_ns = env.Root;

                NameReference prop_a_typename = NameReference.Create("TA");
                NameReference prop_b_typename = NameReference.Create("TB");

                root_ns.AddBuilder(TypeBuilder.Create(
                                       NameDefinition.Create(NameFactory.TupleTypeName,
                                                             TemplateParametersBuffer.Create().Add("TA", VarianceMode.In).Add("TB", VarianceMode.Out).Values))
                                   .SetModifier(EntityModifier.Mutable)

                                   .With(ExpressionFactory.BasicConstructor(new[] { "adata", "bdata" },
                                                                            new[] { NameReference.Create("TA"), NameReference.Create("TB") }))

                                   .With(PropertyBuilder.CreateAutoFull(env.Options, "adata", prop_a_typename, Undef.Create()))

                                   .With(PropertyBuilder.CreateAutoFull(env.Options, "bdata", prop_b_typename, Undef.Create())));

                resolver = NameResolver.Create(env);

                Assert.IsTrue(resolver.ErrorManager.HasError(ErrorCode.VarianceForbiddenPosition, prop_a_typename));
                Assert.IsTrue(resolver.ErrorManager.HasError(ErrorCode.VarianceForbiddenPosition, prop_b_typename));
                Assert.AreEqual(2, resolver.ErrorManager.Errors.Count);
            }

            return(resolver);
        }