Sfoglia il codice sorgente

point "not final return" error to a call position for call-site inlining
closes #9015

Aleksandr Kuzmenko 5 anni fa
parent
commit
e8717877aa

+ 7 - 1
src/optimization/inline.ml

@@ -687,7 +687,13 @@ let rec type_inline ctx cf f ethis params tret config p ?(self_calling_closure=f
 		| TVar (v,eo) ->
 			{ e with eexpr = TVar ((state#declare v).i_subst,opt (map false false) eo)}
 		| TReturn eo when not state#in_local_fun ->
-			if not term then error "Cannot inline a not final return" po;
+			if not term then begin
+				match cf.cf_kind with
+				| Method MethInline ->
+					error "Cannot inline a not final return" po
+				| _ ->
+					error ("Function " ^ cf.cf_name ^ " cannot be inlined because of a not final return") p
+			end;
 			(match eo with
 			| None -> mk (TConst TNull) f.tf_type p
 			| Some e ->

+ 13 - 0
tests/misc/projects/Issue9015/Main.hx

@@ -0,0 +1,13 @@
+class Main {
+	static function main() {
+		inline test();
+	}
+
+	static function test():String {
+		switch Std.random(10) {
+			case 0: return 'hello';
+			case _:
+		}
+		return 'world';
+	}
+}

+ 1 - 0
tests/misc/projects/Issue9015/compile-fail.hxml

@@ -0,0 +1 @@
+--main Main

+ 1 - 0
tests/misc/projects/Issue9015/compile-fail.hxml.stderr

@@ -0,0 +1 @@
+Main.hx:3: characters 3-16 : Function test cannot be inlined because of a not final return