From 253c23b2d141d11c429315649a89aa34611d9873 Mon Sep 17 00:00:00 2001 From: Simon Krajewski Date: Fri, 17 Nov 2023 16:55:19 +0100 Subject: [PATCH] [typer] fix module static resolution closes #11385 --- src/typing/fields.ml | 5 ++++- tests/unit/src/unit/issues/Issue11385.hx | 9 +++++++++ tests/unit/src/unit/issues/misc/Issue11385LibraryData.hx | 7 +++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 tests/unit/src/unit/issues/Issue11385.hx create mode 100644 tests/unit/src/unit/issues/misc/Issue11385LibraryData.hx diff --git a/src/typing/fields.ml b/src/typing/fields.ml index 2352299bc0e..523d42e6f16 100644 --- a/src/typing/fields.ml +++ b/src/typing/fields.ml @@ -533,7 +533,8 @@ let type_field cfg ctx e i p mode (with_type : WithType.t) = ) | _ -> raise Not_found in - let type_field_by_module e t = match e.eexpr with + let type_field_by_module e t = + match e.eexpr with | TTypeExpr mt -> let infos = t_infos mt in if snd infos.mt_path <> snd infos.mt_module.m_path then raise Not_found; @@ -541,6 +542,8 @@ let type_field cfg ctx e i p mode (with_type : WithType.t) = begin match infos.mt_module.m_statics with | Some c when PMap.mem i c.cl_statics -> let cf = PMap.find i c.cl_statics in + (* We cannot use e here because in the case of module statics the type could be different (issue #11385). *) + let e = type_module_type ctx (TClassDecl c) e.epos in field_access e cf (FHStatic c) | _ -> let t = Typeload.find_type_in_module infos.mt_module i in diff --git a/tests/unit/src/unit/issues/Issue11385.hx b/tests/unit/src/unit/issues/Issue11385.hx new file mode 100644 index 00000000000..258526b0947 --- /dev/null +++ b/tests/unit/src/unit/issues/Issue11385.hx @@ -0,0 +1,9 @@ +package unit.issues; + +import unit.issues.misc.Issue11385LibraryData; + +class Issue11385 extends Test { + function test() { + eq("Hello World", Issue11385LibraryData.isCommitHash()); + } +} diff --git a/tests/unit/src/unit/issues/misc/Issue11385LibraryData.hx b/tests/unit/src/unit/issues/misc/Issue11385LibraryData.hx new file mode 100644 index 00000000000..7b447f3c619 --- /dev/null +++ b/tests/unit/src/unit/issues/misc/Issue11385LibraryData.hx @@ -0,0 +1,7 @@ +package unit.issues.misc; + +class Issue11385LibraryData {} + +function isCommitHash() { + return "Hello World"; +}