Skip to content

Commit

Permalink
[flow][type_sig] fix singleton type from_annot field
Browse files Browse the repository at this point in the history
Summary:
`as const` singleton types are considered originating from annotations, whereas those corresponding to const-declarations are not. This did not matter before, since we did not attempt to do any generalization, but it will soon, so I'm fixing here.

Changelog: [internal]

Reviewed By: gkz

Differential Revision: D70763515

fbshipit-source-id: 0a5e133950a3b19b3cdd38bad46b07608e111035
  • Loading branch information
panagosg7 authored and facebook-github-bot committed Mar 7, 2025
1 parent 0c99955 commit d08c3fd
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/typing/type_sig_merge.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1138,7 +1138,7 @@ and merge_value ?(as_const = false) ?(const_decl = false) env file = function
| StringLit (loc, lit) ->
if as_const || const_decl then
let reason = Reason.(mk_annot_reason (RStringLit (OrdinaryName lit)) loc) in
Type.(DefT (reason, SingletonStrT { from_annot = false; value = Reason.OrdinaryName lit }))
Type.(DefT (reason, SingletonStrT { from_annot = as_const; value = Reason.OrdinaryName lit }))
else
let reason = Reason.(mk_reason RString loc) in
Type.(DefT (reason, StrGeneralT AnyLiteral))
Expand All @@ -1152,7 +1152,7 @@ and merge_value ?(as_const = false) ?(const_decl = false) env file = function
| NumberLit (loc, num, raw) ->
if as_const || const_decl then
let reason = Reason.(mk_annot_reason (RNumberLit raw) loc) in
Type.(DefT (reason, SingletonNumT { from_annot = false; value = (num, raw) }))
Type.(DefT (reason, SingletonNumT { from_annot = as_const; value = (num, raw) }))
else
let reason = Reason.(mk_reason RNumber loc) in
Type.(DefT (reason, NumGeneralT AnyLiteral))
Expand All @@ -1162,7 +1162,7 @@ and merge_value ?(as_const = false) ?(const_decl = false) env file = function
| BigIntLit (loc, bigint, raw) ->
if as_const || const_decl then
let reason = Reason.(mk_annot_reason (RBigIntLit raw) loc) in
Type.(DefT (reason, SingletonBigIntT { from_annot = false; value = (bigint, raw) }))
Type.(DefT (reason, SingletonBigIntT { from_annot = as_const; value = (bigint, raw) }))
else
let reason = Reason.(mk_reason RBigInt loc) in
Type.(DefT (reason, BigIntGeneralT AnyLiteral))
Expand All @@ -1172,7 +1172,7 @@ and merge_value ?(as_const = false) ?(const_decl = false) env file = function
| BooleanLit (loc, lit) ->
if as_const || const_decl then
let reason = Reason.(mk_annot_reason (RBooleanLit lit) loc) in
Type.(DefT (reason, SingletonBoolT { from_annot = false; value = lit }))
Type.(DefT (reason, SingletonBoolT { from_annot = as_const; value = lit }))
else
let reason = Reason.(mk_reason RBoolean loc) in
Type.(DefT (reason, BoolGeneralT))
Expand Down

0 comments on commit d08c3fd

Please sign in to comment.