浏览代码

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 年之前
父节点
当前提交
4190eebcb1
共有 3 个文件被更改,包括 11 次插入1 次删除
  1. 1 1
      src/typing/typeloadFields.ml
  2. 8 0
      tests/misc/projects/Issue11005/Main.hx
  3. 2 0
      tests/misc/projects/Issue11005/compile.hxml

+ 1 - 1
src/typing/typeloadFields.ml

@@ -917,7 +917,7 @@ module TypeBinding = struct
 						e
 					end in
 					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
 					begin match c.cl_kind with
 						| 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