Skip to content

Commit 733a3e9

Browse files
committed
#pragma downcast support for array types
1 parent d7dc3a6 commit 733a3e9

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

src/UnityScript.Tests/PragmaTestFixture.boo

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ class PragmaTestFixture(AbstractIntegrationTestFixture):
1010
def downcast_plus_strict_1():
1111
RunTestCase("tests/pragma/downcast-plus-strict-1.js")
1212

13+
[Test]
14+
def downcast_plus_strict_for_arrays():
15+
RunTestCase("tests/pragma/downcast-plus-strict-for-arrays.js")
16+
1317
[Test]
1418
def implicit_1():
1519
RunTestCase("tests/pragma/implicit-1.js")

src/UnityScript/Steps/InitializeUnityScriptTypeSystem.boo

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ class InitializeUnityScriptTypeSystem(InitializeTypeSystemServices):
1111
return UnityCallableResolutionService(Context)
1212

1313
override def CreateDowncastPermissions():
14-
return UnityDowncastPermissions(Context)
14+
return UnityDowncastPermissions()

src/UnityScript/Steps/UnityDowncastPermissions.boo

100644100755
+10-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
namespace UnityScript.Steps
22

33
import Boo.Lang.Compiler
4+
import Boo.Lang.Compiler.TypeSystem
45
import Boo.Lang.Compiler.TypeSystem.Services
56

67
class UnityDowncastPermissions(DowncastPermissions):
78

89
[property(Enabled)] _enabled = false
910

10-
def constructor(context as CompilerContext):
11-
super(context)
11+
override def CanBeReachedByDowncast(expectedType as IType, actualType as IType):
12+
if expectedType.IsArray and actualType.IsArray and IsDowncastAllowed():
13+
return CanBeReachedByArrayDowncast(expectedType, actualType)
14+
return super(expectedType, actualType)
1215

13-
override def IsDowncastAllowed():
16+
override protected def IsDowncastAllowed():
1417
return _enabled or super()
18+
19+
private def CanBeReachedByArrayDowncast(expectedType as IArrayType, actualType as IArrayType):
20+
return expectedType.GetArrayRank() == actualType.GetArrayRank() \
21+
and CanBeReachedByDowncast(expectedType.GetElementType(), actualType.GetElementType())

tests/pragma/downcast-plus-strict-for-arrays.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Bar
2+
Bar[]
33
*/
44
#pragma strict
55
#pragma downcast

0 commit comments

Comments
 (0)