public IErrorReporter ErrorGetterOverridesNothing() { NameResolver resolver = null; foreach (var mutability in Options.AllMutabilityModes) { var env = Language.Environment.Create(new Options().SetMutability(mutability)); var root_ns = env.Root; Property property = PropertyBuilder.Create(env.Options, "getMe", () => NameFactory.Int64NameReference()) .With(PropertyMemberBuilder.CreateGetter(Block.CreateStatement(Return.Create(Int64Literal.Create("2")))) .Modifier(EntityModifier.Override)); var type = root_ns.AddBuilder(TypeBuilder.Create("Last") .SetModifier(EntityModifier.Base) .With(property)); resolver = NameResolver.Create(env); Assert.AreEqual(1, resolver.ErrorManager.Errors.Count); Assert.IsTrue(resolver.ErrorManager.HasError(ErrorCode.NothingToOverride, property.Getter)); } return(resolver); }
/// <summary> /// CTOR - from builder /// </summary> /// <param name="builder">Builder</param> public PropertyMember(PropertyMemberBuilder builder) : base(builder) { IsIndexer = builder.IsIndexer; IsReadOnly = builder.IsReadOnly; IsWriteOnly = builder.IsWriteOnly; GetterModifier = builder.GetterModifier; SetterModifier = builder.SetterModifier; TypeRef = builder.TypeRef; Parameters = builder.Parameters; }
public IInterpreter OverridingMethodWithIndexerGetter() { var interpreter = new Interpreter.Interpreter(); foreach (var mutability in Options.AllMutabilityModes) { var env = Language.Environment.Create(new Options() { AllowInvalidMainResult = true, DebugThrowOnError = true }.SetMutability(mutability)); var root_ns = env.Root; root_ns.AddBuilder(TypeBuilder.CreateInterface("IProvider") .With(FunctionBuilder.CreateDeclaration(NameFactory.PropertyIndexerName, ExpressionReadMode.ReadRequired, NameFactory.Int64NameReference()) .Parameters(FunctionParameter.Create("x", NameFactory.Int64NameReference())))); root_ns.AddBuilder(TypeBuilder.Create("Middle") .Parents("IProvider") .SetModifier(EntityModifier.Base) .With(FunctionBuilder.Create(NameFactory.PropertyIndexerName, ExpressionReadMode.ReadRequired, NameFactory.Int64NameReference(), Block.CreateStatement(Return.Create(Int64Literal.Create("500")))) .SetModifier(EntityModifier.Override | EntityModifier.UnchainBase) .Parameters(FunctionParameter.Create("x", NameFactory.Int64NameReference(), ExpressionReadMode.CannotBeRead)))); root_ns.AddBuilder(TypeBuilder.Create("Last") .Parents("Middle") .SetModifier(EntityModifier.Base) .With(PropertyBuilder.CreateIndexer(env.Options, NameFactory.Int64NameReference()) .Parameters(FunctionParameter.Create("x", NameFactory.Int64NameReference(), ExpressionReadMode.CannotBeRead)) .With(PropertyMemberBuilder.CreateIndexerGetter(Block.CreateStatement(Return.Create(Int64Literal.Create("2")))) .Modifier(EntityModifier.Override | EntityModifier.UnchainBase)))); root_ns.AddBuilder(FunctionBuilder.Create( "main", ExpressionReadMode.OptionalUse, NameFactory.Int64NameReference(), Block.CreateStatement(new IExpression[] { VariableDeclaration.CreateStatement("p", NameFactory.PointerNameReference("IProvider"), ExpressionFactory.HeapConstructor("Last")), Return.Create(FunctionCall.Create(NameReference.Create("p", NameFactory.PropertyIndexerName), FunctionArgument.Create(Int64Literal.Create("18")))) }))); ExecValue result = interpreter.TestRun(env); Assert.AreEqual(2L, result.RetValue.PlainValue); } return(interpreter); }
public IErrorReporter ErrorCustomGetterWithInitialization() { NameResolver resolver = null; foreach (var mutability in Options.AllMutabilityModes) { var env = Language.Environment.Create(new Options() { }.SetMutability(mutability)); var root_ns = env.Root; // error: custom getter (with no setter) + post initialization Property property = PropertyBuilder.Create(env.Options, "x", () => NameFactory.Nat8NameReference()) .With(PropertyMemberBuilder.CreateGetter(Block.CreateStatement(Return.Create(Nat8Literal.Create("3"))))) .SetModifier(EntityModifier.PostInitialization); root_ns.AddBuilder(TypeBuilder.Create("Point") .With(property)); root_ns.AddBuilder(FunctionBuilder.Create( "main", ExpressionReadMode.OptionalUse, NameFactory.Nat8NameReference(), Block.CreateStatement(new IExpression[] { VariableDeclaration.CreateStatement("p", null, ConstructorCall.StackConstructor(NameReference.Create("Point")) // this cannot be executed but do not report an error for it, because the type has to be fixed first .Init("x", Nat8Literal.Create("17")) .Build()), Return.Create(NameReference.Create(NameReference.Create("p"), "x")) }))); resolver = NameResolver.Create(env); Assert.AreEqual(1, resolver.ErrorManager.Errors.Count); Assert.IsTrue(resolver.ErrorManager.HasError(ErrorCode.PostInitializedCustomGetter, property)); } return(resolver); }