Browse Source

New() and Delete() cannot specify return types. Fixes #339.

woollybah 7 years ago
parent
commit
fd1e552d5b
4 changed files with 13 additions and 5 deletions
  1. 3 1
      ctranslator.bmx
  2. 5 0
      decl.bmx
  3. 4 3
      iparser.bmx
  4. 1 1
      parser.bmx

+ 3 - 1
ctranslator.bmx

@@ -4893,7 +4893,9 @@ End Rem
 			func :+ funcDecl.ident
 		End If
 
-		func :+ TransIfcType(funcDecl.retType, funcDecl.ModuleScope().IsSuperStrict())
+		If Not TNewDecl(funcDecl) Then
+			func :+ TransIfcType(funcDecl.retType, funcDecl.ModuleScope().IsSuperStrict())
+		End If
 
 		' function args
 		func :+ TransIfcArgs(funcDecl)

+ 5 - 0
decl.bmx

@@ -1965,9 +1965,13 @@ Type TFuncDecl Extends TBlockDecl
 		Local strictVoidToInt:Int = False
 
 		If isCtor() Or isDtor() Then
+			If retTypeExpr And Not TVoidType(retTypeExpr) Then
+				Err ident + "() cannot specify a return type"
+			End If
 			If ClassScope() And ClassScope().IsInterface() Then
 				Err ident + "() cannot be declared in an Interface."
 			End If
+			If IsCtor() retTypeExpr=New TObjectType.Create( TNewDecl(Self).cDecl )
 		End If
 
 		'semant ret type
@@ -2207,6 +2211,7 @@ End Type
 Type TNewDecl Extends TFuncDecl
 
 	Field chainedCtor:TNewExpr
+	Field cdecl:TClassDecl
 	
 	Method OnCopy:TDecl(deep:Int = True)
 		Local args:TArgDecl[]=argDecls[..]

+ 4 - 3
iparser.bmx

@@ -691,7 +691,7 @@ Type TIParser
 				'_toker.
 				NextToke
 				
-				Local decl:TFuncDecl = ParseFuncDecl( _toke,method_attrs|FUNC_METHOD )
+				Local decl:TFuncDecl = ParseFuncDecl( _toke,method_attrs|FUNC_METHOD, ,classDecl )
 				'If decl.IsCtor() decl.retTypeExpr=New TObjectType.Create( classDecl )
 				classDecl.InsertDecl decl
 				
@@ -862,7 +862,7 @@ Type TIParser
 		Return str
 	End Method
 
-	Method ParseFuncDecl:TFuncDecl( toke$,attrs:Int, returnType:TType = Null )
+	Method ParseFuncDecl:TFuncDecl( toke$,attrs:Int, returnType:TType = Null, classDecl:TClassDecl = Null )
 		SetErr
 
 		'If toke Parse toke
@@ -881,7 +881,7 @@ Type TIParser
 					NextToke
 					attrs:|FUNC_CTOR
 					attrs:&~FUNC_METHOD
-					ty=ParseDeclType(attrs, True)
+					ParseDeclType(attrs, True)
 				Else
 					If _toker._tokeType = TOKE_STRINGLIT Then
 						id = ParseStringLit()
@@ -1018,6 +1018,7 @@ Type TIParser
 		Local funcDecl:TFuncDecl
 		If attrs & FUNC_CTOR Then
 			funcDecl = New TNewDecl.CreateF( id,ty,args,attrs )
+			TNewDecl(funcDecl).cdecl = classDecl
 		Else
 			If fdecl Then
 				funcDecl = fdecl

+ 1 - 1
parser.bmx

@@ -2795,6 +2795,7 @@ End Rem
 		Local funcDecl:TFuncDecl
 		If attrs & FUNC_CTOR Then
 			funcDecl=New TNewDecl.CreateF( id,ty,args,attrs )
+			TNewDecl(funcDecl).cdecl = classdecl
 		Else
 			'If fdecl Then
 			'	funcDecl = fdecl
@@ -3267,7 +3268,6 @@ End Rem
 					Err "Structs can only contain fields."
 				EndIf
 				Local decl:TFuncDecl=ParseFuncDecl( _toke,method_attrs | abst_attrs,classDecl )
-				If decl.IsCtor() decl.retTypeExpr=New TObjectType.Create( classDecl )
 				classDecl.InsertDecl decl
 			Case "function"
 				'If (attrs & CLASS_INTERFACE)