2
0
Эх сурвалжийг харах

Improved error messages. Fixes #176

woollybah 9 жил өмнө
parent
commit
45e74f5e36
2 өөрчлөгдсөн 41 нэмэгдсэн , 19 устгасан
  1. 14 3
      decl.bmx
  2. 27 16
      expr.bmx

+ 14 - 3
decl.bmx

@@ -1025,6 +1025,7 @@ End Rem
 	Method FindFuncDecl:TFuncDecl( ident$,argExprs:TExpr[] = Null,explicit:Int=False, isArg:Int = False, isIdentExpr:Int = False, throwOnNotMatched:Int = False, maxSearchDepth:Int )
 'DebugLog "FindFuncDecl : " + ident
 'If ident = "new" Then DebugStop
+		Local foundIdentMatch:Int
 		Local funcs:TFuncDeclList
 
 		' does ident exist?
@@ -1157,6 +1158,8 @@ End Rem
 				Local exact:Int=True
 				Local possible:Int=True
 				
+				foundIdentMatch = True
+				
 				' we found a matching name - this is probably the one we mean...
 				If isArg Then
 					'match=func
@@ -1279,10 +1282,18 @@ End Rem
 				If t t:+","
 				If argExprs[i] t:+argExprs[i].exprType.ToString()
 			Next
-			If throwOnNotMatched Then
-				Throw "Unable to find overload for "+ident+"("+t+"). " + errorDetails
+			If foundIdentMatch Then
+				If throwOnNotMatched Then
+					Throw "Unable to find overload for "+ident+"("+t+"). " + errorDetails
+				Else
+					Err "Unable to find overload for "+ident+"("+t+"). " + errorDetails
+				End If
 			Else
-				Err "Unable to find overload for "+ident+"("+t+"). " + errorDetails
+				If throwOnNotMatched Then
+					Throw "Function "+ident+"("+t+") not found."
+				Else
+					Err "Function "+ident+"("+t+") not found."
+				End If
 			End If
 		EndIf
 		

+ 27 - 16
expr.bmx

@@ -752,7 +752,7 @@ Type TNewObjectExpr Extends TExpr
 		
 		If it Then
 			'Local parts:String[] = it.ident.ToLower().Split(".")
-			
+
 			Local i:Int = 0
 			
 			While i < parts.length And parts[i] <> classDecl.IdentLower() And parts[i] <> "self"
@@ -765,6 +765,8 @@ Type TNewObjectExpr Extends TExpr
 			Local cdecl:TClassDecl = classDecl
 			Local eType:TType = objTy
 			
+			Local errorDetails:String
+			
 			While i < parts.length
 				Local id:String = parts[i]
 				i :+ 1
@@ -778,6 +780,9 @@ Type TNewObjectExpr Extends TExpr
 						Throw errorMessage
 					Else
 						' couldn't find an exact match, look elsewhere
+						If errorMessage.StartsWith("Unable") Then
+							errorDetails = errorMessage
+						End If
 					End If
 				End Try
 				If fdecl Then
@@ -793,24 +798,30 @@ Type TNewObjectExpr Extends TExpr
 				End If
 				
 				' find other member decl (field, etc)
-				Local decl:TVarDecl = TVarDecl(cdecl.GetDecl(id))
-				If decl Then
-					Local tmp:TLocalDecl=New TLocalDecl.Create( "", eType, expr,, True )
-					Local varExpr:TExpr = New TMemberVarExpr.Create(New TVarExpr.Create( tmp ), decl).Semant()
-					expr = New TStmtExpr.Create( New TDeclStmt.Create( tmp ), varExpr ).Semant()
-					eType = decl.ty
-					If TObjectType(eType) Then
-						cdecl = TObjectType(expr.exprType).classdecl
-					End If
-					If TArrayType(eType) Or TStringType(eType) Then
-						cdecl = eType.GetClass()
+				If Not errorDetails Then
+					Local decl:TVarDecl = TVarDecl(cdecl.GetDecl(id))
+					If decl Then
+						Local tmp:TLocalDecl=New TLocalDecl.Create( "", eType, expr,, True )
+						Local varExpr:TExpr = New TMemberVarExpr.Create(New TVarExpr.Create( tmp ), decl).Semant()
+						expr = New TStmtExpr.Create( New TDeclStmt.Create( tmp ), varExpr ).Semant()
+						eType = decl.ty
+						If TObjectType(eType) Then
+							cdecl = TObjectType(expr.exprType).classdecl
+						End If
+						If TArrayType(eType) Or TStringType(eType) Then
+							cdecl = eType.GetClass()
+						End If
+						Continue
 					End If
-					Continue
-				End If
-				
+				End If	
+
 				' didn't match member or function??
 				' probably an error...
-				Err "Identifier '" + id + "' not found."
+				If errorDetails Then
+					Err errorDetails
+				Else
+					Err "Identifier '" + id + "' not found."
+				End If
 			Wend
 			
 			Return expr