-
Notifications
You must be signed in to change notification settings - Fork 471
compiler: update typecore; tests: add VariantCoercionConstructUsed; d… #7839
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
992088e
7f1f3c4
1844a6c
6012c86
5d5e111
bfcef55
2c6a0e9
7da7c05
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3018,6 +3018,36 @@ and type_expect_ ~context ?in_function ?(recarg = Rejected) env sexp ty_expected | |
raise (Error (loc, env, Not_subtype (tr1, tr2, ctx)))); | ||
(arg, ty', cty') | ||
in | ||
(* After a successful coercion, if we coerced between concrete variant | ||
types, mark the intersection of constructors as positively used for the | ||
target type to avoid spurious "constructor ... is never used" warnings | ||
when values are introduced via coercions. *) | ||
(match | ||
( (try Some (Ctype.extract_concrete_typedecl env arg.exp_type) | ||
with Not_found -> None), | ||
try Some (Ctype.extract_concrete_typedecl env ty') | ||
with Not_found -> None ) | ||
with | ||
| Some (_p_src, _p_src_conc, src_decl), Some (_p_tgt, p_tgt_conc, tgt_decl) | ||
-> ( | ||
match (src_decl.type_kind, tgt_decl.type_kind) with | ||
| Type_variant src_cons, Type_variant tgt_cons -> | ||
let src_names = | ||
List.map | ||
(fun (c : Types.constructor_declaration) -> Ident.name c.cd_id) | ||
src_cons | ||
in | ||
let has_src name = List.exists (fun n -> n = name) src_names in | ||
let tgt_ty_name = Path.last p_tgt_conc in | ||
|
||
List.iter | ||
(fun (c : Types.constructor_declaration) -> | ||
let cname = Ident.name c.cd_id in | ||
if has_src cname then | ||
Env.mark_constructor_used Env.Positive env tgt_ty_name tgt_decl | ||
cname) | ||
tgt_cons | ||
| _ -> ()) | ||
| _ -> ()); | ||
rue | ||
{ | ||
exp_desc = arg.exp_desc; | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Generated by ReScript, PLEASE EDIT WITH CARE | ||
|
||
|
||
function upcast(x) { | ||
return x; | ||
} | ||
|
||
export { | ||
upcast, | ||
} | ||
/* No side effect */ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Repro for incorrect "constructor ... is never used" warning with coercions | ||
// This should compile cleanly without warnings when coercing from a -> b. | ||
|
||
type a = A | B | ||
|
||
type b = | ||
| ...a | ||
| C | ||
|
||
let upcast = (x: a): b => (x :> b) | ||
|
||
let _ = upcast(A) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These matches could be done in one match, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@codex can this be done in one match?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To use Codex here, create an environment for this repo.