浏览代码

Fixed final class extensions not working.

Mark Sibly 7 年之前
父节点
当前提交
9de9392649
共有 3 个文件被更改,包括 28 次插入33 次删除
  1. 15 3
      src/mx2cc/class.monkey2
  2. 1 1
      src/mx2cc/func.monkey2
  3. 12 29
      src/mx2cc/test.monkey2

+ 15 - 3
src/mx2cc/class.monkey2

@@ -179,10 +179,22 @@ Class ClassType Extends Type
 					If Not superType Throw New SemantEx( "Type '"+type.ToString()+"' is not a valid super class type" )
 					
 					If superType.cdecl.kind<>cdecl.kind Throw New SemantEx( "'"+cdecl.kind.Capitalize()+"' cannot extend '"+superType.cdecl.kind.Capitalize()+"'" )
-					
+						
 					If superType.state=SNODE_SEMANTING Throw New SemantEx( "Cyclic inheritance error for '"+ToString()+"'",cdecl )
-					
-					If superType.cdecl.IsFinal Throw New SemantEx( "Superclass '"+superType.ToString()+"' is final" )
+						
+					If cdecl.IsExtension
+						
+						If superType.cdecl.ident.StartsWith( "@" )	'fix me - this is yuck!
+							Throw New SemantEx( "Built-in types cannot be extended" )
+						Endif
+						
+					Else
+						
+						If superType.cdecl.IsFinal
+							Throw New SemantEx( "Superclass '"+superType.ToString()+"' is final and cannot be extended" )
+						End
+							
+					End
 					
 					extendsVoid=superType.extendsVoid
 					

+ 1 - 1
src/mx2cc/func.monkey2

@@ -179,7 +179,7 @@ Class FuncValue Extends Value
 		
 			selfType=cscope.ctype
 
-			If selfType.cdecl.IsExtension selfType=selfType.superType
+			If selfType.cdecl.IsExtension And selfType.superType selfType=selfType.superType
 			
 			selfValue=New SelfValue( selfType,Self )
 			

+ 12 - 29
src/mx2cc/test.monkey2

@@ -1,43 +1,26 @@
-Interface I
-	
-	Method A:Int()
-	
-End
 
-Interface I2
+Class C Final
 	
-	Method B:Int()
+	Protected
 	
-End
-
-Interface J Extends I,I2
+	Field x:Int
 	
 End
 
-Class C Implements J
-	
-	Method A:Int()
-		Return 1
-	End
+Class C Extension
 	
-	Method B:Int()
-		Return 1
+	Method Test:Int()
+		
+		Return x
 	End
 	
 End
-
-Class D
-End
-
-Class Test<T> Where T Implements INumeric
-
-End
-
-Function Main()
 	
-	Local test:Test<Int>
+Function Main()
 	
-	Local j:J=New C
+	Local c:=New C
 	
-	print j.A()
+	Print c.Test()
+
 End
+