TUnionType.st
changeset 0 db69a8d8b368
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TUnionType.st	Sat Aug 22 00:17:35 2015 +0100
@@ -0,0 +1,44 @@
+"{ Package: 'jv:tea' }"
+
+"{ NameSpace: Smalltalk }"
+
+TType subclass:#TUnionType
+	instanceVariableNames:'types'
+	classVariableNames:''
+	poolDictionaries:''
+	category:'Languages-Tea-Type System'
+!
+
+!TUnionType class methodsFor:'instance creation'!
+
+with: type1 with: type2
+    ^ self new initializeWith: type1 and: type2
+
+    "Created: / 21-08-2015 / 18:38:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!TUnionType methodsFor:'accessing'!
+
+types
+    ^ types
+! !
+
+!TUnionType methodsFor:'initialization'!
+
+initializeWith: type1 with: type2
+    type1 isUnionType 
+        ifTrue: [ types := type1 types copy  ]
+        ifFalse:[ types := Array with: type1 ].
+    type2 isUnionType 
+        ifTrue: [ types := types , type2 types ]
+        ifFalse:[ types := types copyWith: type2 ].
+
+    "Created: / 21-08-2015 / 18:39:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!TUnionType methodsFor:'testing'!
+
+isUnionType
+    ^ true
+! !
+