Selaa lähdekoodia

Improved handling of interface method return types. Fixes #269.

woollybah 8 vuotta sitten
vanhempi
commit
584be4f4d5
2 muutettua tiedostoa jossa 38 lisäystä ja 3 poistoa
  1. 2 1
      ctranslator.bmx
  2. 36 2
      decl.bmx

+ 2 - 1
ctranslator.bmx

@@ -3982,8 +3982,9 @@ End Rem
 							If func.IsMethod() Then
 							
 								For Local f:TFuncDecl = EachIn fdecls
+
 									Mungdecl f
-									If f.ident = func.ident And func.EqualsFunc(f) Then
+									If f.ident = func.ident And f.EqualsFunc(func) Then
 										Emit "_" + f.munged + ","
 										Exit
 									End If

+ 36 - 2
decl.bmx

@@ -1719,7 +1719,7 @@ Type TFuncDecl Extends TBlockDecl
 			' matching args?
 			If EqualsArgs( decl ) Then
 				' matching return type?
-				If TObjectType(retType) Or TArrayType(retType) Then
+				If TObjectType(retType) Or TArrayType(retType) Or TStringType(retType) Then
 					Return retType.EqualsType( decl.retType ) Or retType.ExtendsType( decl.retType )' Or decl.retType.EqualsType( retType )) And EqualsArgs( decl )
 				Else
 					Return retType.EqualsType( decl.retType )
@@ -2664,7 +2664,8 @@ End Rem
 						
 						While cdecl And Not found
 							For Local decl2:TFuncDecl=EachIn cdecl.SemantedMethods( decl.ident )
-								If decl.EqualsFunc( decl2 )
+								' equals (or extends - for object types)
+								If decl2.EqualsFunc( decl )
 									found=True
 									Exit
 								EndIf
@@ -2679,12 +2680,45 @@ End Rem
 					Next
 				Next
 			End If
+		Else
+			' check for compatible overloads, etc.
+
+			Local impls:TList=New TList
+
+			CheckInterface(Self, impls)
+			
 		EndIf
 		
 		PopErr
 		
 	End Method
 	
+	Method CheckInterface(cdecl:TClassDecl, impls:TList)
+		While cdecl
+			For Local idecl:TClassDecl = EachIn cdecl.implments
+				CheckInterface(idecl, impls)
+			Next
+		
+			For Local decl:TFuncDecl=EachIn cdecl.SemantedMethods()
+				Local found:Int
+				For Local decl2:TFuncDecl=EachIn impls
+					If decl.IdentLower() = decl2.IdentLower()
+						If Not decl2.EqualsFunc( decl )
+							Err "Cannot mix incompatible method signatures." + decl2.ToString() + " vs " + decl.ToString() + "."
+						Else
+							found = True
+						End If
+					EndIf
+				Next
+				If Not found Then
+					impls.AddLast decl
+				End If
+				'EndIf
+			Next
+			cdecl=cdecl.superClass
+		Wend
+	End Method
+	
 	Method GetFieldOffset(decl:TFieldDecl)
 		
 		Local ty:TType = decl.declTy