Skip to content

Commit 487cf79

Browse files
committed
main script functions should also be virtual by default - gets rid of nonsensical warnings/errors for scripts that extend other scripts
1 parent d8fcfa4 commit 487cf79

12 files changed

+132
-11
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
namespace UnityScript.Tests
2+
3+
import Boo.Lang.Compiler
4+
import Boo.Lang.Compiler.IO
5+
6+
import UnityScript
7+
8+
import NUnit.Framework
9+
10+
[TestFixture]
11+
class MultiFileTestFixture:
12+
13+
[Test]
14+
def NoWarningsOrErrorForEmptyClassInheritingEmptyScript():
15+
16+
script1 = """
17+
class Message extends System.Object {
18+
}"""
19+
20+
script2 = """
21+
class ServerMessage extends Message {
22+
}"""
23+
24+
result = CompileScripts(StringInput("Message.js", script1), StringInput("ServerMessage.js", script2))
25+
Assert.AreEqual(0, len(result.Warnings), result.Warnings.ToString())
26+
Assert.AreEqual(0, len(result.Errors), result.Errors.ToString())
27+
28+
def CompileScripts(*scripts as (ICompilerInput)):
29+
compiler = UnityScriptCompiler()
30+
compiler.Parameters.Pipeline = UnityScriptCompiler.Pipelines.CompileToMemory()
31+
compiler.Parameters.ScriptBaseType = object
32+
compiler.Parameters.ScriptMainMethod = "Main"
33+
for input in scripts:
34+
compiler.Parameters.Input.Add(input)
35+
return compiler.Run()
Original file line numberDiff line numberDiff line change
@@ -1 +1,87 @@
1-
<?xml version="1.0" encoding="utf-8"?><Project DefaultTargets="Build" ToolsVersion="3.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <ProductVersion>9.0.21022</ProductVersion> <SchemaVersion>2.0</SchemaVersion> <ProjectGuid>{95AA127C-D606-4836-BCBF-EE424BB441C9}</ProjectGuid> <OutputType>Library</OutputType> <RootNamespace>UnityScript.Tests</RootNamespace> <UsePartialTypes>false</UsePartialTypes> <AssemblyName>UnityScript.Tests</AssemblyName> <TargetFrameworkVersion>v3.5</TargetFrameworkVersion> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <DebugSymbols>true</DebugSymbols> <DebugType>full</DebugType> <OutputPath>bin\Debug</OutputPath> <ErrorReport>prompt</ErrorReport> <ducky>false</ducky> <culture /> <genwarnings>false</genwarnings> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <DebugType>none</DebugType> <OutputPath>bin\Release</OutputPath> <ErrorReport>prompt</ErrorReport> <ducky>false</ducky> <culture /> <genwarnings>false</genwarnings> </PropertyGroup> <ItemGroup> <Reference Include="System" /> <Reference Include="nunit.framework, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77" /> <Reference Include="Boo.Lang, Version=2.0.9.4, Culture=neutral, PublicKeyToken=32c39770e9a21a67" /> <Reference Include="Boo.Lang.Compiler, Version=2.0.9.4, Culture=neutral, PublicKeyToken=32c39770e9a21a67" /> <Reference Include="Boo.Lang.Parser, Version=2.0.9.4, Culture=neutral, PublicKeyToken=32c39770e9a21a67" /> <Reference Include="Boo.Lang.PatternMatching, Version=2.0.9.4, Culture=neutral, PublicKeyToken=32c39770e9a21a67" /> <Reference Include="Boo.Lang.Useful, Version=2.0.9.4, Culture=neutral, PublicKeyToken=32c39770e9a21a67" /> <Reference Include="Boo.Lang.Extensions, Version=2.0.9.4, Culture=neutral, PublicKeyToken=32c39770e9a21a67" /> </ItemGroup> <ItemGroup> <Compile Include="Class1.boo" /> <Compile Include="AbstractCompilerTestFixture.boo" /> <Compile Include="AbstractIntegrationTestFixture.boo" /> <Compile Include="AbstractSemanticsTestFixture.boo" /> <Compile Include="AssemblyInfo.boo" /> <Compile Include="CommandLineOptionsTestFixture.boo" /> <Compile Include="ErrorMessagesTestFixture.boo" /> <Compile Include="ErrorMessagesTestFixture.Generated.boo" /> <Compile Include="EvalTestFixture.boo" /> <Compile Include="ExpandoTestFixture.boo" /> <Compile Include="GenericsTestFixture.Generated.boo" /> <Compile Include="Globals.boo" /> <Compile Include="IntegrationTestFixture.boo" /> <Compile Include="MonoBehaviour.boo" /> <Compile Include="ParserTestFixture.boo" /> <Compile Include="ParserTestFixture.Generated.boo" /> <Compile Include="PEVerify.boo" /> <Compile Include="PragmaTestFixture.boo" /> <Compile Include="RuntimeTestFixture.boo" /> <Compile Include="SemanticsTestFixture.boo" /> <Compile Include="StackTraceTestFixture.boo" /> <Compile Include="StackTraceTestFixture.Generated.boo" /> <Compile Include="UnityScriptCompilerFactoryTestFixture.boo" /> <Compile Include="UnityScriptCompilerTestFixture.boo" /> <Compile Include="UsTestFixture.boo" /> </ItemGroup> <ItemGroup> <ProjectReference Include="..\UnityScript\UnityScript.booproj"> <Project>{A4F2FB34-6254-473D-9EB4-FAF062AF1AEB}</Project> <Name>UnityScript</Name> </ProjectReference> <ProjectReference Include="..\UnityScript.Lang\UnityScript.Lang.booproj"> <Project>{2784E7F4-5206-4BF9-99CD-96B1D94D0E19}</Project> <Name>UnityScript.Lang</Name> </ProjectReference> <ProjectReference Include="..\UnityScript.Tests.CSharp\UnityScript.Tests.CSharp.csproj"> <Project>{EF5AE116-19DD-42DC-847A-7BD3EE49AB01}</Project> <Name>UnityScript.Tests.CSharp</Name> </ProjectReference> <ProjectReference Include="..\us\us.booproj"> <Project>{2C02FCE8-42AD-474F-804E-F39C5164A1DE}</Project> <Name>us</Name> </ProjectReference> </ItemGroup></Project>
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="3.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<ProductVersion>9.0.21022</ProductVersion>
7+
<SchemaVersion>2.0</SchemaVersion>
8+
<ProjectGuid>{95AA127C-D606-4836-BCBF-EE424BB441C9}</ProjectGuid>
9+
<OutputType>Library</OutputType>
10+
<RootNamespace>UnityScript.Tests</RootNamespace>
11+
<UsePartialTypes>false</UsePartialTypes>
12+
<AssemblyName>UnityScript.Tests</AssemblyName>
13+
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<DebugSymbols>true</DebugSymbols>
17+
<DebugType>full</DebugType>
18+
<OutputPath>bin\Debug</OutputPath>
19+
<ErrorReport>prompt</ErrorReport>
20+
<ducky>false</ducky>
21+
<culture />
22+
<genwarnings>false</genwarnings>
23+
</PropertyGroup>
24+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
25+
<DebugType>none</DebugType>
26+
<OutputPath>bin\Release</OutputPath>
27+
<ErrorReport>prompt</ErrorReport>
28+
<ducky>false</ducky>
29+
<culture />
30+
<genwarnings>false</genwarnings>
31+
</PropertyGroup>
32+
<ItemGroup>
33+
<Reference Include="System" />
34+
<Reference Include="nunit.framework, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77" />
35+
<Reference Include="Boo.Lang.Compiler, Version=2.0.9.4, Culture=neutral, PublicKeyToken=32c39770e9a21a67" />
36+
<Reference Include="Boo.Lang.Parser, Version=2.0.9.4, Culture=neutral, PublicKeyToken=32c39770e9a21a67" />
37+
<Reference Include="Boo.Lang.PatternMatching, Version=2.0.9.4, Culture=neutral, PublicKeyToken=32c39770e9a21a67" />
38+
<Reference Include="Boo.Lang.Useful, Version=2.0.9.4, Culture=neutral, PublicKeyToken=32c39770e9a21a67" />
39+
<Reference Include="Boo.Lang.Extensions, Version=2.0.9.4, Culture=neutral, PublicKeyToken=32c39770e9a21a67" />
40+
<Reference Include="Boo.Lang.Interpreter, Version=2.0.9.4, Culture=neutral, PublicKeyToken=32c39770e9a21a67" />
41+
</ItemGroup>
42+
<ItemGroup>
43+
<Compile Include="AbstractCompilerTestFixture.boo" />
44+
<Compile Include="AbstractIntegrationTestFixture.boo" />
45+
<Compile Include="AbstractSemanticsTestFixture.boo" />
46+
<Compile Include="AssemblyInfo.boo" />
47+
<Compile Include="CommandLineOptionsTestFixture.boo" />
48+
<Compile Include="ErrorMessagesTestFixture.boo" />
49+
<Compile Include="ErrorMessagesTestFixture.Generated.boo" />
50+
<Compile Include="EvalTestFixture.boo" />
51+
<Compile Include="ExpandoTestFixture.boo" />
52+
<Compile Include="GenericsTestFixture.Generated.boo" />
53+
<Compile Include="Globals.boo" />
54+
<Compile Include="IntegrationTestFixture.boo" />
55+
<Compile Include="MonoBehaviour.boo" />
56+
<Compile Include="ParserTestFixture.boo" />
57+
<Compile Include="ParserTestFixture.Generated.boo" />
58+
<Compile Include="PEVerify.boo" />
59+
<Compile Include="PragmaTestFixture.boo" />
60+
<Compile Include="RuntimeTestFixture.boo" />
61+
<Compile Include="SemanticsTestFixture.boo" />
62+
<Compile Include="StackTraceTestFixture.boo" />
63+
<Compile Include="StackTraceTestFixture.Generated.boo" />
64+
<Compile Include="UnityScriptCompilerFactoryTestFixture.boo" />
65+
<Compile Include="UnityScriptCompilerTestFixture.boo" />
66+
<Compile Include="UsTestFixture.boo" />
67+
<Compile Include="MultiFileTestFixture.boo" />
68+
</ItemGroup>
69+
<ItemGroup>
70+
<ProjectReference Include="..\UnityScript\UnityScript.booproj">
71+
<Project>{A4F2FB34-6254-473D-9EB4-FAF062AF1AEB}</Project>
72+
<Name>UnityScript</Name>
73+
</ProjectReference>
74+
<ProjectReference Include="..\UnityScript.Lang\UnityScript.Lang.booproj">
75+
<Project>{2784E7F4-5206-4BF9-99CD-96B1D94D0E19}</Project>
76+
<Name>UnityScript.Lang</Name>
77+
</ProjectReference>
78+
<ProjectReference Include="..\UnityScript.Tests.CSharp\UnityScript.Tests.CSharp.csproj">
79+
<Project>{EF5AE116-19DD-42DC-847A-7BD3EE49AB01}</Project>
80+
<Name>UnityScript.Tests.CSharp</Name>
81+
</ProjectReference>
82+
<ProjectReference Include="..\us\us.booproj">
83+
<Project>{2C02FCE8-42AD-474F-804E-F39C5164A1DE}</Project>
84+
<Name>us</Name>
85+
</ProjectReference>
86+
</ItemGroup>
87+
</Project>

src/UnityScript/Steps/ApplySemantics.boo

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ class ApplySemantics(AbstractVisitorCompilerStep):
160160

161161
def CreateMainMethod(module as Module):
162162
method = Method(module.LexicalInfo, Name: ScriptMainMethod)
163-
method.Modifiers = TypeMemberModifiers.Public
163+
method.Modifiers = TypeMemberModifiers.Public | TypeMemberModifiers.Virtual
164164

165165
stmts = module.Globals.Statements
166166
if len(stmts) > 0: method.LexicalInfo = Copy(stmts[0].LexicalInfo)

tests/semantics/Magic2Class.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ partial class Magic2Class:
99
public virtual def bar():
1010
pass
1111
12-
public def Awake():
12+
public virtual def Awake():
1313
pass
1414
*/
1515
class Magic2Class

tests/semantics/MagicClass.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ partial class MagicClass(AnotherMagicClass):
1212
public def constructor(value):
1313
pass
1414
15-
public def Awake():
15+
public virtual def Awake():
1616
pass
1717
*/
1818
class MagicClass extends AnotherMagicClass {

tests/semantics/class-3.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ partial class class-3(UnityScript.Tests.MonoBehaviour):
2929
3030
public p as Person = Person('Eric Idle', 42)
3131
32-
public def Awake():
32+
public virtual def Awake():
3333
print(p.ToString())
3434
*/
3535

tests/semantics/coroutine.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ partial class coroutine(UnityScript.Tests.MonoBehaviour):
99
yield 1
1010
yield 2
1111
12-
public def Awake():
12+
public virtual def Awake():
1313
enumerate = spam()
1414
for e in enumerate:
1515
print(e)

tests/semantics/fields-1.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Fields:
99
1010
partial class fields-1(UnityScript.Tests.MonoBehaviour):
1111
12-
public def Awake():
12+
public virtual def Awake():
1313
pass
1414
*/
1515
class Fields {

tests/semantics/functions-2.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ partial class functions-2(UnityScript.Tests.MonoBehaviour):
1111
private def eggs():
1212
print(spam(3))
1313
14-
public def Awake():
14+
public virtual def Awake():
1515
eggs()
1616
*/
1717

tests/semantics/magic-members.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ partial class magic-members(UnityScript.Tests.MonoBehaviour):
55
66
public value = 5
77
8-
public def Awake():
8+
public virtual def Awake():
99
if 1:
1010
otherValue1 = 7
1111
else:

tests/semantics/single-update-function.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ partial class single-update-function(UnityScript.Tests.MonoBehaviour):
66
public virtual def Update():
77
pass
88
9-
public def Awake():
9+
public virtual def Awake():
1010
pass
1111
*/
1212
function Update() {}

tests/semantics/variables.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ partial class variables(UnityScript.Tests.MonoBehaviour):
55
66
public value = 5
77
8-
public def Awake():
8+
public virtual def Awake():
99
otherValue = 7
1010
*/
1111

0 commit comments

Comments
 (0)