From 94e89f76869baef5ecc08814a6ca25eeaeae48b7 Mon Sep 17 00:00:00 2001 From: neoeinstein Date: Sat, 17 Nov 2007 05:15:04 +0000 Subject: [PATCH] Various with statics and PreErrorChecking * BOO-916: Disallowed 'abstract final'; emit warning on 'static' keyword modifying member of static class * BOO-918: Static classes make members static. * Various improved checks on modifiers for various types, including modifier checking on structs. * 'static' disallowed on struct and interface definition * Default constructor is ^not^ added to constructorless static classes (They can't be instantiated) git-svn-id: https://svn.codehaus.org/boo/boo/trunk@2755 2c1201b4-01cd-e047-a400-b836ae1fbc61 --- src/Boo.Lang.Compiler/CompilerErrorFactory.cs | 18 +- src/Boo.Lang.Compiler/CompilerWarningFactory.cs | 229 +++++++++++---------- .../Steps/NormalizeTypeAndMemberDefinitions.cs | 2 +- src/Boo.Lang.Compiler/Steps/PreErrorChecking.cs | 66 +++--- src/Boo.Lang/Resources/strings.txt | 7 +- tests/testcases/errors/BCE0131-2.boo | 10 + tests/testcases/errors/BCE0150-1.boo | 15 +- tests/testcases/errors/BCE0151-1.boo | 11 + tests/testcases/errors/BCE0151-2.boo | 7 + tests/testcases/errors/BCE0152-1.boo | 10 - tests/testcases/errors/BCE0153-1.boo | 11 - tests/testcases/integration/types/static-1.boo | 14 ++ tests/testcases/integration/types/static-2.boo | 18 ++ tests/testcases/warnings/BCW0013-1.boo | 6 + tests/testcases/warnings/BCW0013-2.boo | 8 + tests/testcases/warnings/BCW0013-3.boo | 12 ++ 16 files changed, 257 insertions(+), 187 deletions(-) create mode 100644 tests/testcases/errors/BCE0131-2.boo create mode 100644 tests/testcases/errors/BCE0151-1.boo create mode 100644 tests/testcases/errors/BCE0151-2.boo delete mode 100644 tests/testcases/errors/BCE0152-1.boo delete mode 100644 tests/testcases/errors/BCE0153-1.boo create mode 100644 tests/testcases/integration/types/static-1.boo create mode 100644 tests/testcases/integration/types/static-2.boo create mode 100644 tests/testcases/warnings/BCW0013-1.boo create mode 100644 tests/testcases/warnings/BCW0013-2.boo create mode 100644 tests/testcases/warnings/BCW0013-3.boo diff --git a/src/Boo.Lang.Compiler/CompilerErrorFactory.cs b/src/Boo.Lang.Compiler/CompilerErrorFactory.cs index a6237d2c..9aecec64 100644 --- a/src/Boo.Lang.Compiler/CompilerErrorFactory.cs +++ b/src/Boo.Lang.Compiler/CompilerErrorFactory.cs @@ -800,24 +800,14 @@ namespace Boo.Lang.Compiler return new CompilerError("BCE0149", SafeLexicalInfo(node), argument, parameter, baseType); } - public static CompilerError AbstractFinalClassCanOnlyHaveStatics(Node node, string typeName, string memberName) - { - return new CompilerError("BCE0150", SafeLexicalInfo(node), typeName, memberName); - } - - public static CompilerError AbstractFinalClassCannotUseVirtualOverrideOrAbstract(Node node, string typeName, string memberName) + public static CompilerError CantBeMarkedFinal(Node node) { - return new CompilerError("BCE0151", SafeLexicalInfo(node), typeName, memberName); + return new CompilerError("BCE0150", SafeLexicalInfo(node)); } - public static CompilerError AbstractFinalClassCannotHaveInstanceConstructor(Node node, string typeName) - { - return new CompilerError("BCE0152", SafeLexicalInfo(node), typeName); - } - - public static CompilerError CantBeMarkedFinal(Node node) + public static CompilerError CantBeMarkedStatic(Node node) { - return new CompilerError("BCE0153", SafeLexicalInfo(node)); + return new CompilerError("BCE0151", SafeLexicalInfo(node)); } public static string ToStringList(System.Collections.IEnumerable names) diff --git a/src/Boo.Lang.Compiler/CompilerWarningFactory.cs b/src/Boo.Lang.Compiler/CompilerWarningFactory.cs index 09eeb048..b1171fd5 100644 --- a/src/Boo.Lang.Compiler/CompilerWarningFactory.cs +++ b/src/Boo.Lang.Compiler/CompilerWarningFactory.cs @@ -1,112 +1,117 @@ -#region license -// Copyright (c) 2004, Rodrigo B. de Oliveira (rbo@acm.org) -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without modification, -// are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// * Neither the name of Rodrigo B. de Oliveira nor the names of its -// contributors may be used to endorse or promote products derived from this -// software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#endregion - -using System; -using System.Text; -using Boo.Lang.Compiler.Ast; -using Boo.Lang.Compiler.TypeSystem; - -namespace Boo.Lang.Compiler -{ - public class CompilerWarningFactory - { - private CompilerWarningFactory() - { - } - - public static CompilerWarning CustomWarning(LexicalInfo lexicalInfo, string msg) - { - return new CompilerWarning(lexicalInfo, msg); - } - - public static CompilerWarning CustomWarning(string msg) - { - return new CompilerWarning(msg); - } - - public static CompilerWarning AbstractMemberNotImplemented(Node node, string typeName, string memberName) - { - return new CompilerWarning("BCW0001", node.LexicalInfo, typeName, memberName); - } - - public static CompilerWarning ModifiersInLabelsHaveNoEffect(Node node) - { - return new CompilerWarning("BCW0002", node.LexicalInfo); - } - - public static CompilerWarning UnusedLocalVariable(Node node, string name) - { - return new CompilerWarning("BCW0003", node.LexicalInfo, name); - } - - public static CompilerWarning IsInsteadOfIsa(Node node) - { - return new CompilerWarning("BCW0004", node.LexicalInfo); - } - - public static CompilerWarning InvalidEventUnsubscribe(Node node, string eventName, CallableSignature expected) - { - return new CompilerWarning("BCW0005", node.LexicalInfo, eventName, expected); - } - - public static CompilerWarning AssignmentToTemporary(Node node) - { - return new CompilerWarning("BCW0006", node.LexicalInfo); - } - - public static CompilerWarning EqualsInsteadOfAssign(BinaryExpression node) - { - return new CompilerWarning("BCW0007", node.LexicalInfo, node.ToCodeString()); - } - - public static CompilerWarning DuplicateNamespace(Import import, string name) - { - return new CompilerWarning("BCW0008", import.LexicalInfo, name); - } - - public static CompilerWarning HaveBothKeyFileAndAttribute(Node node) - { - return new CompilerWarning("BCW0009", node.LexicalInfo); - } - - public static CompilerWarning HaveBothKeyNameAndAttribute(Node node) - { - return new CompilerWarning("BCW0010", node.LexicalInfo); - } - - public static CompilerWarning AbstractMemberNotImplementedStubCreated(Node node, string typeName, string memberName) - { - return new CompilerWarning("BCW0011", node.LexicalInfo, typeName, memberName); - } - - public static CompilerWarning Obsolete(Node node, string memberName, string message) - { - return new CompilerWarning("BCW0012", node.LexicalInfo, memberName, message); - } - } -} +#region license +// Copyright (c) 2004, Rodrigo B. de Oliveira (rbo@acm.org) +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of Rodrigo B. de Oliveira nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#endregion + +using System; +using System.Text; +using Boo.Lang.Compiler.Ast; +using Boo.Lang.Compiler.TypeSystem; + +namespace Boo.Lang.Compiler +{ + public class CompilerWarningFactory + { + private CompilerWarningFactory() + { + } + + public static CompilerWarning CustomWarning(LexicalInfo lexicalInfo, string msg) + { + return new CompilerWarning(lexicalInfo, msg); + } + + public static CompilerWarning CustomWarning(string msg) + { + return new CompilerWarning(msg); + } + + public static CompilerWarning AbstractMemberNotImplemented(Node node, string typeName, string memberName) + { + return new CompilerWarning("BCW0001", node.LexicalInfo, typeName, memberName); + } + + public static CompilerWarning ModifiersInLabelsHaveNoEffect(Node node) + { + return new CompilerWarning("BCW0002", node.LexicalInfo); + } + + public static CompilerWarning UnusedLocalVariable(Node node, string name) + { + return new CompilerWarning("BCW0003", node.LexicalInfo, name); + } + + public static CompilerWarning IsInsteadOfIsa(Node node) + { + return new CompilerWarning("BCW0004", node.LexicalInfo); + } + + public static CompilerWarning InvalidEventUnsubscribe(Node node, string eventName, CallableSignature expected) + { + return new CompilerWarning("BCW0005", node.LexicalInfo, eventName, expected); + } + + public static CompilerWarning AssignmentToTemporary(Node node) + { + return new CompilerWarning("BCW0006", node.LexicalInfo); + } + + public static CompilerWarning EqualsInsteadOfAssign(BinaryExpression node) + { + return new CompilerWarning("BCW0007", node.LexicalInfo, node.ToCodeString()); + } + + public static CompilerWarning DuplicateNamespace(Import import, string name) + { + return new CompilerWarning("BCW0008", import.LexicalInfo, name); + } + + public static CompilerWarning HaveBothKeyFileAndAttribute(Node node) + { + return new CompilerWarning("BCW0009", node.LexicalInfo); + } + + public static CompilerWarning HaveBothKeyNameAndAttribute(Node node) + { + return new CompilerWarning("BCW0010", node.LexicalInfo); + } + + public static CompilerWarning AbstractMemberNotImplementedStubCreated(Node node, string typeName, string memberName) + { + return new CompilerWarning("BCW0011", node.LexicalInfo, typeName, memberName); + } + + public static CompilerWarning Obsolete(Node node, string memberName, string message) + { + return new CompilerWarning("BCW0012", node.LexicalInfo, memberName, message); + } + + public static CompilerWarning StaticClassMemberRedundantlyMarkedStatic(Node node, string typeName, string memberName) + { + return new CompilerWarning("BCW0013", node.LexicalInfo, typeName, memberName); + } + } +} diff --git a/src/Boo.Lang.Compiler/Steps/NormalizeTypeAndMemberDefinitions.cs b/src/Boo.Lang.Compiler/Steps/NormalizeTypeAndMemberDefinitions.cs index 2cf3b438..48b4a3e4 100755 --- a/src/Boo.Lang.Compiler/Steps/NormalizeTypeAndMemberDefinitions.cs +++ b/src/Boo.Lang.Compiler/Steps/NormalizeTypeAndMemberDefinitions.cs @@ -63,7 +63,7 @@ namespace Boo.Lang.Compiler.Steps override public void LeaveClassDefinition(ClassDefinition node) { LeaveTypeDefinition(node); - if (!node.HasInstanceConstructor) + if (!node.HasInstanceConstructor && !node.IsStatic) { node.Members.Add(AstUtil.CreateConstructor(node, TypeMemberModifiers.Public)); } diff --git a/src/Boo.Lang.Compiler/Steps/PreErrorChecking.cs b/src/Boo.Lang.Compiler/Steps/PreErrorChecking.cs index 28319d2a..f62dbf9f 100755 --- a/src/Boo.Lang.Compiler/Steps/PreErrorChecking.cs +++ b/src/Boo.Lang.Compiler/Steps/PreErrorChecking.cs @@ -49,46 +49,46 @@ namespace Boo.Lang.Compiler.Steps override public void LeaveField(Field node) { + MakeStaticIfNeeded(node); CheckMemberName(node); CantBeMarkedAbstract(node); CantBeMarkedPartial(node); - CheckMustBeStatic(node); } override public void LeaveProperty(Property node) { + MakeStaticIfNeeded(node); CheckMemberName(node); CantBeMarkedTransient(node); CantBeMarkedPartial(node); CheckExplicitImpl(node); CheckModifierCombination(node); - CheckMustBeStatic(node); } override public void LeaveConstructor(Constructor node) { + MakeStaticIfNeeded(node); CantBeMarkedTransient(node); CantBeMarkedPartial(node); CannotReturnValue(node); - CheckMustBeStatic(node); } override public void LeaveMethod(Method node) { + MakeStaticIfNeeded(node); CheckMemberName(node); CantBeMarkedTransient(node); CantBeMarkedPartial(node); CheckExplicitImpl(node); CheckModifierCombination(node); - CheckMustBeStatic(node); } override public void LeaveEvent(Event node) { + MakeStaticIfNeeded(node); CheckMemberName(node); CantBeMarkedPartial(node); CheckModifierCombination(node); - CheckMustBeStatic(node); } override public void LeaveInterfaceDefinition(InterfaceDefinition node) @@ -98,20 +98,36 @@ namespace Boo.Lang.Compiler.Steps CantBeMarkedTransient(node); CantBeMarkedPartial(node); CantBeMarkedFinal(node); + CantBeMarkedStatic(node); } override public void LeaveCallableDefinition(CallableDefinition node) { + MakeStaticIfNeeded(node); CheckMemberName(node); CantBeMarkedAbstract(node); CantBeMarkedTransient(node); CantBeMarkedPartial(node); - CheckMustBeStatic(node); + } + + public override void LeaveStructDefinition(StructDefinition node) + { + CheckMemberName(node); + CantBeMarkedAbstract(node); + CantBeMarkedFinal(node); + CantBeMarkedStatic(node); + CantBeMarkedPartial(node); } override public void LeaveClassDefinition(ClassDefinition node) { + CheckModifierCombination(node); CheckMemberName(node); + + if(node.IsStatic) + { + node.Modifiers |= TypeMemberModifiers.Abstract | TypeMemberModifiers.Final; + } } override public void LeaveTryStatement(TryStatement node) @@ -202,34 +218,19 @@ namespace Boo.Lang.Compiler.Steps } } - void CheckMustBeStatic(TypeMember node) + void MakeStaticIfNeeded(TypeMember node) { - if(IsAbstractFinal(node.DeclaringType)) + if(node.DeclaringType.IsStatic) { - if(!node.IsStatic) + if(node.IsStatic) { - if(node is Constructor) - { - Error(CompilerErrorFactory.AbstractFinalClassCannotHaveInstanceConstructor(node, node.DeclaringType.Name)); - } - else - { - Error(CompilerErrorFactory.AbstractFinalClassCanOnlyHaveStatics(node, node.DeclaringType.Name, node.Name)); - } - } - - if(node.IsOverride || node.IsVirtual || node.IsAbstract) - { - Error(CompilerErrorFactory.AbstractFinalClassCannotUseVirtualOverrideOrAbstract(node, node.DeclaringType.Name, node.Name)); + Warnings.Add(CompilerWarningFactory.StaticClassMemberRedundantlyMarkedStatic(node, node.DeclaringType.Name, node.Name)); } + + node.Modifiers |= TypeMemberModifiers.Static; } } - - bool IsAbstractFinal(TypeDefinition node) - { - return node.IsFinal && node.IsAbstract; - } - + void CheckExplicitImpl(IExplicitMember member) { ExplicitMemberInfo ei = member.ExplicitInfo; @@ -254,6 +255,7 @@ namespace Boo.Lang.Compiler.Steps InvalidCombination(member, TypeMemberModifiers.Static, TypeMemberModifiers.Abstract); InvalidCombination(member, TypeMemberModifiers.Static, TypeMemberModifiers.Virtual); InvalidCombination(member, TypeMemberModifiers.Static, TypeMemberModifiers.Override); + InvalidCombination(member, TypeMemberModifiers.Abstract, TypeMemberModifiers.Final); if (member.NodeType != NodeType.Field) { @@ -279,5 +281,13 @@ namespace Boo.Lang.Compiler.Steps Error(CompilerErrorFactory.CantBeMarkedPartial(member)); } } + + void CantBeMarkedStatic(TypeMember member) + { + if (member.IsStatic) + { + Error(CompilerErrorFactory.CantBeMarkedStatic(member)); + } + } } } diff --git a/src/Boo.Lang/Resources/strings.txt b/src/Boo.Lang/Resources/strings.txt index b87c1768..f5880421 100644 --- a/src/Boo.Lang/Resources/strings.txt +++ b/src/Boo.Lang/Resources/strings.txt @@ -149,10 +149,8 @@ BCE0146=The type '{0}' must be a reference type in order to substitute the gener BCE0147=The type '{0}' must be a value type in order to substitute the generic parameter '{1}'. BCE0148=The type '{0}' must have a public default constructor in order to substitute the generic parameter '{1}'. BCE0149=The type '{0}' must derive from '{2}' in order to substitute the generic parameter '{1}'. -BCE0150='{0}' is marked 'abstract final' and cannot contain instance member '{1}'; all members must be marked static. -BCE0151='{0}' is marked 'abstract final' and cannot contain virtual, overriden, or abstract member '{0}'. -BCE0152='{0}' is marked 'abstract final' and can only have a static constructor. -BCE0153='final' can not be applied to interface definitions. +BCE0150='final' can not be applied to interface definitions. +BCE0151='static' can not be applied to interface or struct definitions. ;Compiler warnings BCW0000=WARNING: {0} @@ -168,6 +166,7 @@ BCW0009=WARNING: The -keyfile option will override your AssemblyKeyFile attribut BCW0010=WARNING: The -keycontainer option will override your AssemblyKeyName attribute. BCW0011=WARNING: Type '{0}' does not provide an implementation for '{1}', a stub has been created. BCW0012=WARNING: '{0}' is obsolete. {1} +BCW0013=WARNING: '{1}' on static type '{0}' is redundantly marked static. All members of static types are automatically assumed to be static. ; BooC Command Line Errors BCE0500=Response file '{0}' listed more than once. diff --git a/tests/testcases/errors/BCE0131-2.boo b/tests/testcases/errors/BCE0131-2.boo new file mode 100644 index 00000000..b42b457a --- /dev/null +++ b/tests/testcases/errors/BCE0131-2.boo @@ -0,0 +1,10 @@ +""" +BCE0131-2.boo(4,22): BCE0131: Invalid combination of modifiers on 'Test': abstract, final. +""" +abstract final class Test: + def Blah(): + print "Blah" + static def Foo(): + print "Foo" + +Test.Foo() diff --git a/tests/testcases/errors/BCE0150-1.boo b/tests/testcases/errors/BCE0150-1.boo index 765d6e4c..36a97c82 100644 --- a/tests/testcases/errors/BCE0150-1.boo +++ b/tests/testcases/errors/BCE0150-1.boo @@ -1,10 +1,11 @@ """ -BCE0150-1.boo(5,7): BCE0150: 'Test' is marked 'abstract final' and cannot contain instance member 'Blah'; all members must be marked static. +BCE0150-1.boo(4,17): BCE0150: 'final' can not be applied to interface definitions. """ -abstract final class Test: - def Blah(): - print "Blah" - static def Foo(): - print "Foo" +final interface IFoo: + def Test() -Test.Foo() +class Bar(IFoo): + def Test(): + print "Test" + +Bar().Test() diff --git a/tests/testcases/errors/BCE0151-1.boo b/tests/testcases/errors/BCE0151-1.boo new file mode 100644 index 00000000..b1efecb0 --- /dev/null +++ b/tests/testcases/errors/BCE0151-1.boo @@ -0,0 +1,11 @@ +""" +BCE0151-1.boo(4,18): BCE0151: 'static' can not be applied to interface or struct definitions. +""" +static interface IFoo: + def Test() + +class Bar(IFoo): + def Test(): + print "Test" + +Bar().Test() diff --git a/tests/testcases/errors/BCE0151-2.boo b/tests/testcases/errors/BCE0151-2.boo new file mode 100644 index 00000000..e81057d4 --- /dev/null +++ b/tests/testcases/errors/BCE0151-2.boo @@ -0,0 +1,7 @@ +""" +BCE0151-2.boo(4,15): BCE0151: 'static' can not be applied to interface or struct definitions. +""" +static struct Foo: + test = 53 + +print Foo.test diff --git a/tests/testcases/errors/BCE0152-1.boo b/tests/testcases/errors/BCE0152-1.boo deleted file mode 100644 index 294e1b43..00000000 --- a/tests/testcases/errors/BCE0152-1.boo +++ /dev/null @@ -1,10 +0,0 @@ -""" -BCE0152-1.boo(5,7): BCE0152: 'Test' is marked 'abstract final' and can only have a static constructor. -""" -abstract final class Test: - def constructor(): - print "Blah" - static def Foo(): - print "Foo" - -Test() diff --git a/tests/testcases/errors/BCE0153-1.boo b/tests/testcases/errors/BCE0153-1.boo deleted file mode 100644 index 56ee05a3..00000000 --- a/tests/testcases/errors/BCE0153-1.boo +++ /dev/null @@ -1,11 +0,0 @@ -""" -BCE0153-1.boo(4,17): BCE0153: 'final' can not be applied to interface definitions. -""" -final interface IFoo: - def Test() - -class Bar(IFoo): - def Test(): - print "Test" - -Bar().Test() diff --git a/tests/testcases/integration/types/static-1.boo b/tests/testcases/integration/types/static-1.boo new file mode 100644 index 00000000..fb11a220 --- /dev/null +++ b/tests/testcases/integration/types/static-1.boo @@ -0,0 +1,14 @@ +""" +-4 +""" +class Test: + static class Foo: + public final green = -4 + + private static def DoTheTest(): + print Foo.green + + def Bar(): + DoTheTest() + +Test().Bar() \ No newline at end of file diff --git a/tests/testcases/integration/types/static-2.boo b/tests/testcases/integration/types/static-2.boo new file mode 100644 index 00000000..237bcc12 --- /dev/null +++ b/tests/testcases/integration/types/static-2.boo @@ -0,0 +1,18 @@ +""" +Baz sees 0 +Foo.Bar() +Baz sees 1 +""" +static class Foo: + i = 0 + + def Bar(): + print "Foo.Bar()" + + def Baz(): + print "Baz sees ${i}" + i += 1 + +Foo.Baz() +Foo.Bar() +Foo.Baz() \ No newline at end of file diff --git a/tests/testcases/warnings/BCW0013-1.boo b/tests/testcases/warnings/BCW0013-1.boo new file mode 100644 index 00000000..b82d9fd6 --- /dev/null +++ b/tests/testcases/warnings/BCW0013-1.boo @@ -0,0 +1,6 @@ +""" +BCW0013-1.boo(5,16): BCW0013: WARNING: 'constructor' on static type 'Test' is redundantly marked static. All members of static types are automatically assumed to be static. +""" +static class Test: + static def constructor(): + print "Static Constructor" diff --git a/tests/testcases/warnings/BCW0013-2.boo b/tests/testcases/warnings/BCW0013-2.boo new file mode 100644 index 00000000..c267e48c --- /dev/null +++ b/tests/testcases/warnings/BCW0013-2.boo @@ -0,0 +1,8 @@ +""" +BCW0013-2.boo(6,12): BCW0013: WARNING: 'eigen' on static type 'Test' is redundantly marked static. All members of static types are automatically assumed to be static. +BCW0013-2.boo(7,16): BCW0013: WARNING: 'DoTheTest' on static type 'Test' is redundantly marked static. All members of static types are automatically assumed to be static. +""" +static class Test: + static eigen = 42 + static def DoTheTest(): + print eigen diff --git a/tests/testcases/warnings/BCW0013-3.boo b/tests/testcases/warnings/BCW0013-3.boo new file mode 100644 index 00000000..37f1b136 --- /dev/null +++ b/tests/testcases/warnings/BCW0013-3.boo @@ -0,0 +1,12 @@ +""" +BCW0013-3.boo(6,29): BCW0013: WARNING: 'green' on static type 'Foo' is redundantly marked static. All members of static types are automatically assumed to be static. +""" +class Test: + static class Foo: + public static final green = -4 + + private static def DoTheTest(): + print Foo.green + + def Bar(): + DoTheTest() -- 2.11.4.GIT