Ejemplo n.º 1
0
        public IErrorReporter ErrorVariableNotUsed()
        {
            NameResolver resolver = null;

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

                VariableDeclaration member = VariableDeclaration.CreateStatement("x", NameFactory.Int64NameReference(),
                                                                                 Int64Literal.Create("5"));
                root_ns.AddBuilder(TypeBuilder.Create("Thing")
                                   .With(member));

                var            decl1      = VariableDeclaration.CreateStatement("s", NameFactory.Int64NameReference(), null);
                var            decl2      = VariableDeclaration.CreateStatement("t", NameFactory.Int64NameReference(), null);
                NameDefinition loop_label = NameDefinition.Create("here");
                var            loop       = Loop.CreateFor(loop_label,
                                                           init: null,
                                                           condition: null,
                                                           step: null,
                                                           body: new IExpression[] { decl1, decl2 });
                var func_def = root_ns.AddBuilder(FunctionBuilder.Create(
                                                      "main",
                                                      ExpressionReadMode.OptionalUse,
                                                      NameFactory.UnitNameReference(),

                                                      Block.CreateStatement(new IExpression[] {
                    loop,
                })));

                resolver = NameResolver.Create(env);

                Assert.AreEqual(4, resolver.ErrorManager.Errors.Count);
                Assert.IsTrue(resolver.ErrorManager.HasError(ErrorCode.BindableNotUsed, decl1.Name));
                Assert.IsTrue(resolver.ErrorManager.HasError(ErrorCode.BindableNotUsed, decl2.Name));
                Assert.IsTrue(resolver.ErrorManager.HasError(ErrorCode.BindableNotUsed, loop_label));
                Assert.IsTrue(resolver.ErrorManager.HasError(ErrorCode.BindableNotUsed, member.Name));
            }

            return(resolver);
        }