Browse Source

Allow non constant "inline" var init with -D no-inline (#11192)

* [tests] add test for #11005

* Allow non constant values for inline variable init if -D no-inline

* [typer] use ctx.doinline instead of -D no-inline

* [tests] update test for 11005
Rudy Ges 2 years ago
parent
commit
f9a7072b7d

+ 1 - 1
src/typing/typeloadFields.ml

@@ -917,7 +917,7 @@ module TypeBinding = struct
 						e
 						e
 					end in
 					end in
 					e
 					e
-				| Var v when v.v_read = AccInline ->
+				| Var v when v.v_read = AccInline && ctx.g.doinline ->
 					let e = require_constant_expression e "Inline variable initialization must be a constant value" in
 					let e = require_constant_expression e "Inline variable initialization must be a constant value" in
 					begin match c.cl_kind with
 					begin match c.cl_kind with
 						| KAbstractImpl a when has_class_field_flag cf CfEnum && a.a_enum ->
 						| KAbstractImpl a when has_class_field_flag cf CfEnum && a.a_enum ->

+ 8 - 0
tests/misc/projects/Issue11005/Main.hx

@@ -0,0 +1,8 @@
+function main() {}
+
+abstract Foo(String) {
+	public inline function new(str:String)
+		this = str;
+}
+
+inline final foo = new Foo("foo");

+ 2 - 0
tests/misc/projects/Issue11005/compile.hxml

@@ -0,0 +1,2 @@
+-main Main
+-D no-inline