Skip to content
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

Version 11.1.4 #7026

Merged
merged 8 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@
> - :house: [Internal]
> - :nail_care: [Polish]

# 11.1.4

- Fix issue where long layout break added a trailing comma in partial application `...`. https://github.com/rescript-lang/rescript-compiler/pull/6949
- Fix incorrect format of function under unary operator. https://github.com/rescript-lang/rescript-compiler/pull/6953
- Fix incorrect incorrect printing of module binding with signature. https://github.com/rescript-lang/rescript-compiler/pull/6963
- Disallow spreading anything but regular variants inside of other variants. https://github.com/rescript-lang/rescript-compiler/pull/6980
- Fix comment removed when function signature has `type` keyword. https://github.com/rescript-lang/rescript-compiler/pull/6997
- Fix parse error on doc comment before "and" in type def. https://github.com/rescript-lang/rescript-compiler/pull/7001
- Fix tuple coercion. https://github.com/rescript-lang/rescript-compiler/pull/7024

# 11.1.3

#### :bug: Bug Fix
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

We've found a bug for you!
/.../fixtures/variant_spread_abstract_type.res:2:15

1 │ type a
2 │ type b = | ...a | Other
3 │

This type is not a valid type to spread. It's only possible to spread other variants.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

We've found a bug for you!
/.../fixtures/variant_spread_extensible_variant.res:2:15

1 │ type a = ..
2 │ type b = | ...a | Other
3 │

This type is not a valid type to spread. It's only possible to spread other variants.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
type a
type b = | ...a | Other
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
type a = ..
type b = | ...a | Other
2 changes: 1 addition & 1 deletion jscomp/common/bs_version.ml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
let version = "11.1.3"
let version = "11.1.4"
let header = "// Generated by ReScript, PLEASE EDIT WITH CARE"
let package_name = ref "rescript"
2 changes: 2 additions & 0 deletions jscomp/ml/typedecl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2184,6 +2184,8 @@ let report_error ppf = function
^ other_variant_text
^ ". Both variants must have the same @tag attribute configuration, or no \
@tag attribute at all")
| Variant_spread_fail Variant_type_spread.InvalidType ->
fprintf ppf "@[This type is not a valid type to spread. It's only possible to spread other variants.@]"
| Variant_spread_fail Variant_type_spread.CouldNotFindType ->
fprintf ppf "@[This type could not be found. It's only possible to spread variants that are known as the spread happens. This means for example that you can't spread variants in recursive definitions.@]"
| Variant_spread_fail Variant_type_spread.HasTypeParams ->
Expand Down
4 changes: 3 additions & 1 deletion jscomp/ml/variant_type_spread.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ let mk_constructor_comes_from_spread_attr () : Parsetree.attribute =
type variant_type_spread_error =
| CouldNotFindType
| HasTypeParams
| InvalidType
| DuplicateConstructor of {
variant_with_overlapping_constructor: string;
overlapping_constructor_name: string;
Expand Down Expand Up @@ -31,6 +32,7 @@ let map_constructors ~(sdecl : Parsetree.type_declaration) ~all_constructors env
in

match type_decl with
| {type_kind = Type_variant [] } -> raise (VariantTypeSpreadError (loc.loc, InvalidType))
| {type_kind = Type_variant cstrs; type_attributes; type_params} ->
if List.length type_params > 0 then
raise (VariantTypeSpreadError (loc.loc, HasTypeParams));
Expand Down Expand Up @@ -83,7 +85,7 @@ let map_constructors ~(sdecl : Parsetree.type_declaration) ~all_constructors env
pcd_args = Pcstr_tuple [];
pcd_name = Location.mkloc cstr.cd_id.name cstr.cd_loc;
}))
| _ -> [c])
| _ -> raise (VariantTypeSpreadError (loc.loc, InvalidType)))
| _ ->
Hashtbl.add all_constructors c.pcd_name.txt ();
[c]
Expand Down
2 changes: 2 additions & 0 deletions jscomp/syntax/src/res_comments_table.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1404,6 +1404,8 @@ and walkExpression expr t comments =
attach t.leading expr.pexp_loc leading;
walkExpression expr t inside;
attach t.trailing expr.pexp_loc trailing
| Pexp_construct ({txt = Longident.Lident "Function$"}, Some returnExpr) ->
walkExpression returnExpr t comments
| _ ->
if isBlockExpr returnExpr then walkExpression returnExpr t comments
else
Expand Down
3 changes: 2 additions & 1 deletion jscomp/syntax/src/res_core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1865,6 +1865,7 @@ and parseConstrainedExprRegion p =
| token when Grammar.isExprStart token -> (
let expr = parseExpr p in
match p.Parser.token with
| ColonGreaterThan -> Some (parseCoercedExpr ~expr p)
| Colon ->
Parser.next p;
let typ = parseTypExpr p in
Expand Down Expand Up @@ -2525,7 +2526,7 @@ and parseAttributesAndBinding (p : Parser.t) =
let comments = p.comments in

match p.Parser.token with
| At -> (
| At | DocComment (_, _) -> (
let attrs = parseAttributes p in
match p.Parser.token with
| And -> attrs
Expand Down
27 changes: 27 additions & 0 deletions jscomp/syntax/src/res_parens.ml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ let unaryExprOperand expr =
Parenthesized
| _ when ParsetreeViewer.hasAwaitAttribute expr.pexp_attributes ->
Parenthesized
| {pexp_desc = Pexp_construct ({txt = Lident "Function$"}, Some expr)}
when ParsetreeViewer.isUnderscoreApplySugar expr ->
Nothing
| {pexp_desc = Pexp_construct ({txt = Lident "Function$"}, Some _)} ->
Parenthesized
| _ -> Nothing)

let binaryExprOperand ~isLhs expr =
Expand Down Expand Up @@ -276,6 +281,11 @@ let fieldExpr expr =
Parenthesized
| _ when ParsetreeViewer.hasAwaitAttribute expr.pexp_attributes ->
Parenthesized
| {pexp_desc = Pexp_construct ({txt = Lident "Function$"}, Some expr)}
when ParsetreeViewer.isUnderscoreApplySugar expr ->
Nothing
| {pexp_desc = Pexp_construct ({txt = Lident "Function$"}, Some _)} ->
Parenthesized
| _ -> Nothing)

let setFieldExprRhs expr =
Expand Down Expand Up @@ -440,6 +450,23 @@ let includeModExpr modExpr =
| Parsetree.Pmod_constraint _ -> true
| _ -> false

let modExprParens modExpr =
match modExpr with
| {
Parsetree.pmod_desc =
Pmod_constraint
( {Parsetree.pmod_desc = Pmod_structure _},
{Parsetree.pmty_desc = Pmty_signature [{psig_desc = Psig_module _}]} );
} ->
false
| {
Parsetree.pmod_desc =
Pmod_constraint
(_, {Parsetree.pmty_desc = Pmty_signature [{psig_desc = Psig_module _}]});
} ->
true
| _ -> false

let arrowReturnTypExpr typExpr =
match typExpr.Parsetree.ptyp_desc with
| Parsetree.Ptyp_arrow _ -> true
Expand Down
2 changes: 2 additions & 0 deletions jscomp/syntax/src/res_parens.mli
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ val callExpr : Parsetree.expression -> kind

val includeModExpr : Parsetree.module_expr -> bool

val modExprParens : Parsetree.module_expr -> bool

val arrowReturnTypExpr : Parsetree.core_type -> bool

val patternRecordRowRhs : Parsetree.pattern -> bool
Expand Down
7 changes: 7 additions & 0 deletions jscomp/syntax/src/res_parsetree_viewer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ let processUncurriedAppAttribute attrs =
in
process false [] attrs

let hasPartialAttribute attrs =
List.exists
(function
| {Location.txt = "res.partial"}, _ -> true
| _ -> false)
attrs

let processPartialAppAttribute attrs =
let rec process partialApp acc attrs =
match attrs with
Expand Down
2 changes: 2 additions & 0 deletions jscomp/syntax/src/res_parsetree_viewer.mli
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ type functionAttributesInfo = {
attributes: Parsetree.attributes;
}

val hasPartialAttribute : Parsetree.attributes -> bool

(* determines whether a function is async and/or uncurried based on the given attributes *)
val processFunctionAttributes : Parsetree.attributes -> functionAttributesInfo

Expand Down
33 changes: 27 additions & 6 deletions jscomp/syntax/src/res_printer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,11 @@ and printModuleBinding ~state ~isRec moduleBinding cmtTbl i =
Doc.concat [Doc.text ": "; printModType ~state modType cmtTbl] )
| modExpr -> (printModExpr ~state modExpr cmtTbl, Doc.nil)
in
let modExprDocParens =
if Parens.modExprParens moduleBinding.pmb_expr then
Doc.concat [Doc.lparen; modExprDoc; Doc.rparen]
else modExprDoc
in
let modName =
let doc = Doc.text moduleBinding.pmb_name.Location.txt in
printComments doc cmtTbl moduleBinding.pmb_name.loc
Expand All @@ -732,7 +737,7 @@ and printModuleBinding ~state ~isRec moduleBinding cmtTbl i =
modName;
modConstraintDoc;
Doc.text " = ";
modExprDoc;
modExprDocParens;
]
in
printComments doc cmtTbl moduleBinding.pmb_loc
Expand Down Expand Up @@ -4120,7 +4125,13 @@ and printPexpApply ~state expr cmtTbl =
let partial, attrs = ParsetreeViewer.processPartialAppAttribute attrs in
let args =
if partial then
let dummy = Ast_helper.Exp.constant (Ast_helper.Const.int 0) in
let loc =
{Asttypes.txt = "res.partial"; Asttypes.loc = expr.pexp_loc}
in
let attr = (loc, Parsetree.PTyp (Ast_helper.Typ.any ())) in
let dummy =
Ast_helper.Exp.constant ~attrs:[attr] (Ast_helper.Const.int 0)
in
args @ [(Asttypes.Labelled "...", dummy)]
else args
in
Expand Down Expand Up @@ -4700,6 +4711,18 @@ and printArguments ~state ~dotted ?(partial = false)
Doc.concat
[(if dotted then Doc.text "(. " else Doc.lparen); argDoc; Doc.rparen]
| args ->
(* Avoid printing trailing comma when there is ... in function application *)
let hasPartialAttr, printedArgs =
List.fold_right
(fun arg (flag, acc) ->
let _, expr = arg in
let hasPartialAttr =
ParsetreeViewer.hasPartialAttribute expr.Parsetree.pexp_attributes
in
let doc = printArgument ~state arg cmtTbl in
(flag || hasPartialAttr, doc :: acc))
args (false, [])
in
Doc.group
(Doc.concat
[
Expand All @@ -4708,11 +4731,9 @@ and printArguments ~state ~dotted ?(partial = false)
(Doc.concat
[
(if dotted then Doc.line else Doc.softLine);
Doc.join
~sep:(Doc.concat [Doc.comma; Doc.line])
(List.map (fun arg -> printArgument ~state arg cmtTbl) args);
Doc.join ~sep:(Doc.concat [Doc.comma; Doc.line]) printedArgs;
]);
(if partial then Doc.nil else Doc.trailingComma);
(if partial || hasPartialAttr then Doc.nil else Doc.trailingComma);
Doc.softLine;
Doc.rparen;
])
Expand Down
10 changes: 9 additions & 1 deletion jscomp/syntax/tests/parsing/grammar/expressions/coerce.res
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
let foo = (x:int) => (x :> int)

let foo = x => (x : t :> int)
let foo = x => (x : t :> int)

let _ = (x : int)

let foo = (x : int, y :> float)

let foo = (x : int, y :> float, z :> int)

let foo = (x : int, y, z :> int)
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
let foo (x : int) = (x :> int)
let foo x = ((x : t) :> int)
let foo x = ((x : t) :> int)
let _ = (x : int)
let foo = ((x : int), (y :> float))
let foo = ((x : int), (y :> float), (z :> int))
let foo = ((x : int), y, (z :> int))
6 changes: 5 additions & 1 deletion jscomp/syntax/tests/parsing/other/docComments.res
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ let q = 11
* is a multi-line
multiline doc comment
*/
type h = int
type h = int

type pathItem = {}
/** Issue 6844: doc comment before "and" */
and operation = {}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ let z = 34[@@res.doc " This is a doc \226\156\133 comment "]
[@@@res.doc {js|And this is a res.doc module annotation|js}]
let q = 11[@@res.doc {js|And this is a res.doc ✅ annotation|js}]
type nonrec h = int[@@res.doc
" This\n * is a multi-line\n multiline doc comment\n "]
" This\n * is a multi-line\n multiline doc comment\n "]
type nonrec pathItem = {
}
and operation = {
}[@@res.doc " Issue 6844: doc comment before \"and\" "]
6 changes: 5 additions & 1 deletion jscomp/syntax/tests/printer/comments/docComments.res
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@ type h = int
@foo @bar @baz let x = 10

/** doc comment and 0 attributes */
let x = 10
let x = 10

type pathItem = {}
/** Issue 6844: doc comment before "and" */
and operation = {}
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ let x = 10

/** doc comment and 0 attributes */
let x = 10

type pathItem = {}
/** Issue 6844: doc comment before "and" */ and operation = {}
34 changes: 34 additions & 0 deletions jscomp/syntax/tests/printer/expr/apply.res
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,37 @@ f(. {

resolve(.)
resolve(. ())

let g = f(
a => LongModuleName.functionWithAlongNameThatWrapsTheEditorToTheNextLinexxxxxxxxxxxxxxxxxxxxxx(a),
b,
c
)

let g = f(
a => LongModuleName.functionWithAlongNameThatWrapsTheEditorToTheNextLinexxxxxxxxxxxxxxxxxxxxxx(a),
b,
c,
...
)

let g = f(
a => LongModuleName.functionWithAlongNameThatWrapsTheEditorToTheNextLinexxxxxxxxxxxxxxxxxxxxxx(a),
b,
c => LongModuleName.functionWithAlongNameThatWrapsTheEditorToTheNextLinexxxxxxxxxxxxxxxxxxxxxx(d, ...),
...
)

let g = f(
a => LongModuleName.functionWithAlongNameThatWrapsTheEditorToTheNextLinexxxxxxxxxxxxxxxxxxxxxx(a, ...),
b,
c => LongModuleName.functionWithAlongNameThatWrapsTheEditorToTheNextLinexxxxxxxxxxxxxxxxxxxxxx(d),
...
)


let g = f(
a => LongModuleName.functionWithAlongNameThatWrapsTheEditorToTheNextLinexxxxxxxxxxxxxxxxxxxxxx(a),
b,
c => LongModuleName.functionWithAlongNameThatWrapsTheEditorToTheNextLinexxxxxxxxxxxxxxxxxxxxxx(d, ...)
)
Loading