Просмотр исходного кода

[nullsafety] don't check extern fields initialization (fixes #10448)

Aleksandr Kuzmenko 4 лет назад
Родитель
Сommit
968ef731c0
3 измененных файлов с 5 добавлено и 1 удалено
  1. 1 0
      extra/CHANGES.txt
  2. 2 1
      src/typing/nullSafety.ml
  3. 2 0
      tests/nullsafety/src/cases/TestStrict.hx

+ 1 - 0
extra/CHANGES.txt

@@ -3,6 +3,7 @@
 	Bugfixes:
 
 	all : fixed compiler crash in complex constraints chains (#10445)
+	nullsafety : fixed false error on extern var fields without initialization (#10448)
 
 2021-10-22 4.2.4:
 

+ 2 - 1
src/typing/nullSafety.ml

@@ -485,7 +485,8 @@ let rec validate_safety_meta report (metadata:Ast.metadata) =
 	Check if specified `field` represents a `var` field which will exist at runtime.
 *)
 let should_be_initialized field =
-	match field.cf_kind with
+	not (has_class_field_flag field CfExtern)
+	&& match field.cf_kind with
 		| Var { v_read = AccNormal | AccInline | AccNo } | Var { v_write = AccNormal | AccNo } -> true
 		| Var _ -> Meta.has Meta.IsVar field.cf_meta
 		| _ -> false

+ 2 - 0
tests/nullsafety/src/cases/TestStrict.hx

@@ -112,6 +112,8 @@ class AllVarsInitializedInConstructor_weHaveClosure_thisShouldBeUsable {
 
 @:build(Validator.checkFields())
 class TestStrict {
+	extern static final something:String;
+
 	public var field:Null<String>;
 	// @:shouldWarn public var publiclyModifiableField:String = 'hello';
 	@:shouldFail var notInitializedField:Int;