Skip to content

Remove meth attribute #7684

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

Merged
merged 7 commits into from
Jul 25, 2025
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
15 changes: 0 additions & 15 deletions .mcp.json

This file was deleted.

1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
- Polish arity mismatch error message a bit. https://github.com/rescript-lang/rescript/pull/7709
- Suggest related functions with the expected arity in errors when it makes sense. https://github.com/rescript-lang/rescript/pull/7712
- Improve error when a constructor expects an inline record. https://github.com/rescript-lang/rescript/pull/7713
- Remove @meth attribute. https://github.com/rescript-lang/rescript/pull/7684

#### :house: Internal

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@ type someMutableFields = {

@genType
type someMethods = {
@meth
"send": string => unit,
@meth
"on": (string, (. int) => unit) => unit,
@meth
"threeargs": (int, string, int) => string,
"twoArgs": (. int, string) => int,
}
Expand Down
7 changes: 2 additions & 5 deletions compiler/frontend/ast_attributes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,12 @@ let process_method_attributes_rev (attrs : t) =
({st with set = Some result}, acc)
| _ -> (st, attr :: acc))

type attr_kind = Nothing | Meth_callback of attr | Method of attr
type attr_kind = Nothing | Meth_callback of attr

let process_attributes_rev (attrs : t) : attr_kind * t =
Ext_list.fold_left attrs (Nothing, [])
(fun (st, acc) (({txt; loc}, _) as attr) ->
Ext_list.fold_left attrs (Nothing, []) (fun (st, acc) (({txt}, _) as attr) ->
match (txt, st) with
| "this", (Nothing | Meth_callback _) -> (Meth_callback attr, acc)
| "meth", (Nothing | Method _) -> (Method attr, acc)
| "this", _ -> Bs_syntaxerr.err loc Conflict_bs_bs_this_bs_meth
| _, _ -> (st, attr :: acc))

let external_attrs =
Expand Down
2 changes: 1 addition & 1 deletion compiler/frontend/ast_attributes.mli
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type ('a, 'b) st = {get: 'a option; set: 'b option}

val process_method_attributes_rev : t -> (bool * bool, [`Get | `No_get]) st * t

type attr_kind = Nothing | Meth_callback of attr | Method of attr
type attr_kind = Nothing | Meth_callback of attr

val process_attributes_rev : t -> attr_kind * t

Expand Down
6 changes: 0 additions & 6 deletions compiler/frontend/ast_core_type_class_type.ml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ let typ_mapper (self : Bs_ast_mapper.mapper) (ty : Parsetree.core_type) =
match fst (Ast_attributes.process_attributes_rev ty.ptyp_attributes) with
| Meth_callback _ ->
Ast_typ_uncurry.to_method_callback_type loc self ~arity ty
| Method _ -> Bs_ast_mapper.default_mapper.typ self ty
| Nothing -> Bs_ast_mapper.default_mapper.typ self ty)
| Ptyp_object (methods, closed_flag) ->
let ( +> ) attr (typ : Parsetree.core_type) =
Expand All @@ -90,8 +89,6 @@ let typ_mapper (self : Bs_ast_mapper.mapper) (ty : Parsetree.core_type) =
let attrs, core_type =
match Ast_attributes.process_attributes_rev attrs with
| Nothing, attrs -> (attrs, ty) (* #1678 *)
| Method _, _ ->
Location.raise_errorf ~loc "%@get/set conflicts with %@meth"
| Meth_callback attr, attrs -> (attrs, attr +> ty)
in
Ast_compatible.object_field name attrs (self.typ self core_type)
Expand All @@ -100,8 +97,6 @@ let typ_mapper (self : Bs_ast_mapper.mapper) (ty : Parsetree.core_type) =
let attrs, core_type =
match Ast_attributes.process_attributes_rev attrs with
| Nothing, attrs -> (attrs, ty)
| Method _, _ ->
Location.raise_errorf ~loc "%@get/set conflicts with %@meth"
| Meth_callback attr, attrs -> (attrs, attr +> ty)
in
Ast_compatible.object_field name attrs
Expand All @@ -113,7 +108,6 @@ let typ_mapper (self : Bs_ast_mapper.mapper) (ty : Parsetree.core_type) =
let attrs, core_type =
match Ast_attributes.process_attributes_rev ptyp_attrs with
| Nothing, attrs -> (attrs, ty)
| Method attr, attrs -> (attrs, attr +> ty)
| Meth_callback attr, attrs -> (attrs, attr +> ty)
in
Ast_compatible.object_field label attrs (self.typ self core_type)
Expand Down
3 changes: 0 additions & 3 deletions compiler/frontend/bs_builtin_ppx.ml
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,6 @@ let expr_mapper ~async_context ~in_function_def (self : mapper)
async_context := (old_in_function_def && !async_context) || async;
in_function_def := true;
Ast_async.make_function_async ~async (default_expr_mapper self e)
| Method _, _ ->
Location.raise_errorf ~loc:e.pexp_loc
"%@meth is not supported in function expression"
| Meth_callback _, pexp_attributes ->
(* FIXME: does it make sense to have a label for [this] ? *)
async_context := false;
Expand Down
2 changes: 1 addition & 1 deletion compiler/frontend/bs_syntaxerr.ml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ let pp_error fmt err =
| Illegal_attribute -> "Illegal attributes"
| Unsupported_predicates -> "unsupported predicates"
| Conflict_bs_bs_this_bs_meth ->
"%@this, %@bs, %@meth can not be applied at the same time"
"%@this and %@bs can not be applied at the same time"
| Duplicated_bs_deriving -> "duplicate @deriving attribute"
| Conflict_attributes -> "conflicting attributes "
| Expect_string_literal -> "expect string literal "
Expand Down
8 changes: 4 additions & 4 deletions compiler/syntax/src/res_parsetree_viewer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,10 @@ let filter_parsing_attrs attrs =
match attr with
| ( {
Location.txt =
( "res.braces" | "ns.braces" | "res.iflet" | "res.ternary"
| "res.await" | "res.template" | "res.taggedTemplate"
| "res.patVariantSpread" | "res.dictPattern"
| "res.inlineRecordDefinition" );
( "meth" | "res.braces" | "ns.braces" | "res.iflet"
| "res.ternary" | "res.await" | "res.template"
| "res.taggedTemplate" | "res.patVariantSpread"
| "res.dictPattern" | "res.inlineRecordDefinition" );
},
_ ) ->
false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
addVariantCaseDeclaration R4 AutoAnnotate.res:15:2 path:+AutoAnnotate.annotatedVariant
Scanning BootloaderResource.cmt Source:BootloaderResource.res
Scanning BucklescriptAnnotations.cmt Source:BucklescriptAnnotations.res
addValueDeclaration +bar BucklescriptAnnotations.res:25:4 path:+BucklescriptAnnotations
addValueDeclaration +f BucklescriptAnnotations.res:26:6 path:+BucklescriptAnnotations
addValueReference BucklescriptAnnotations.res:26:6 --> BucklescriptAnnotations.res:25:11
addValueReference BucklescriptAnnotations.res:25:4 --> BucklescriptAnnotations.res:26:6
addValueDeclaration +bar BucklescriptAnnotations.res:22:4 path:+BucklescriptAnnotations
addValueDeclaration +f BucklescriptAnnotations.res:23:6 path:+BucklescriptAnnotations
addValueReference BucklescriptAnnotations.res:23:6 --> BucklescriptAnnotations.res:22:11
addValueReference BucklescriptAnnotations.res:22:4 --> BucklescriptAnnotations.res:23:6
Scanning ComponentAsProp.cmt Source:ComponentAsProp.res
addValueDeclaration +make ComponentAsProp.res:6:4 path:+ComponentAsProp
addRecordLabelDeclaration title ComponentAsProp.res:6:12 path:+ComponentAsProp.props
Expand Down Expand Up @@ -2594,9 +2594,9 @@ File References
BucklescriptAnnotations is a dead module as all its items are dead.

Warning Dead Value
BucklescriptAnnotations.res:25:1-70
BucklescriptAnnotations.res:22:1-70
bar is never used
<-- line 25
<-- line 22
@dead("bar") let bar = (x: someMethods) => {

Warning Dead Exception
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@ type someMutableFields = {

@genType
type someMethods = {
@meth
"send": string => unit,
@meth
"on": (string, (. int) => unit) => unit,
@meth
"threeargs": (int, string, int) => string,
"twoArgs": (. int, string) => int,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@ type someMutableFields = {

@genType
type someMethods = {
@meth
"send": string => unit,
@meth
"on": (string, int => unit) => unit,
@meth
"threeargs": (int, string, int) => string,
"twoArgs": (int, string) => int,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ type state = {
}

type state = {
@meth
"send": string =>
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,85 +51,85 @@


Syntax error!
syntax_tests/data/parsing/errors/typexpr/bsObjSugar.res:25:1
syntax_tests/data/parsing/errors/typexpr/bsObjSugar.res:24:1

23 @meth
24 │ "send": string =>
25 │ }
26
27 │ type state = {
22type state = {
23 │ "send": string =>
24 │ }
25
26 │ type state = {

I'm missing a type here


Syntax error!
syntax_tests/data/parsing/errors/typexpr/bsObjSugar.res:28:10
syntax_tests/data/parsing/errors/typexpr/bsObjSugar.res:27:10

26
27 │ type state = {
28 │ "age": ,
29 │ "name": string
30 │ }
25
26 │ type state = {
27 │ "age": ,
28 │ "name": string
29 │ }

I'm missing a type here


Syntax error!
syntax_tests/data/parsing/errors/typexpr/bsObjSugar.res:33:15
syntax_tests/data/parsing/errors/typexpr/bsObjSugar.res:32:15

31
32 │ type state = {
33 │ @set "age": ,
34 │ "name": string
35 │ }
30
31 │ type state = {
32 │ @set "age": ,
33 │ "name": string
34 │ }

I'm missing a type here


Syntax error!
syntax_tests/data/parsing/errors/typexpr/bsObjSugar.res:37:25
syntax_tests/data/parsing/errors/typexpr/bsObjSugar.res:36:25

35 │ }
36
37 │ type state = {.. "age": }
38 │ type state = {
39 │ ..
34 │ }
35
36 │ type state = {.. "age": }
37 │ type state = {
38 │ ..

I'm missing a type here


Syntax error!
syntax_tests/data/parsing/errors/typexpr/bsObjSugar.res:40:8-41:8
syntax_tests/data/parsing/errors/typexpr/bsObjSugar.res:39:8-40:8

38 │ type state = {
39 │ ..
40 │ "age"
41 │ "name": string
42 │ }
43
37 │ type state = {
38 │ ..
39 │ "age"
40 │ "name": string
41 │ }
42

Did you forget a `:` here? It signals the start of a type


Syntax error!
syntax_tests/data/parsing/errors/typexpr/bsObjSugar.res:46:3-11
syntax_tests/data/parsing/errors/typexpr/bsObjSugar.res:45:3-11

44 │ type websocket = {
45 │ "id":
46 │ "channel": channelTyp
47 │ }
48
43 │ type websocket = {
44 │ "id":
45 │ "channel": channelTyp
46 │ }
47

I'm missing a type here


Syntax error!
syntax_tests/data/parsing/errors/typexpr/bsObjSugar.res:50:7-51:0
syntax_tests/data/parsing/errors/typexpr/bsObjSugar.res:49:7-50:0

48
49 │ type websocket = {
50 │ "id"
51
47
48 │ type websocket = {
49 │ "id"
50

Did you forget a `:` here? It signals the start of a type

Expand All @@ -141,8 +141,7 @@ type nonrec state =
< url: string ;protocols: [%rescript.typehole ] ;websocket: Websocket.t
>
type nonrec state = < url: string ;protocols: [%rescript.typehole ] >
type nonrec state =
< send: string -> [%rescript.typehole ] (a:1) [@meth ] >
type nonrec state = < send: string -> [%rescript.typehole ] (a:1) >
type nonrec state = < age: [%rescript.typehole ] ;name: string >
type nonrec state = < age: [%rescript.typehole ] [@set ] ;name: string >
type nonrec state = < age: [%rescript.typehole ] ;.. >
Expand Down
10 changes: 5 additions & 5 deletions tests/syntax_tests/data/printer/typexpr/arrow.res
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ type t = @attr (fooWithSuperLongIdentifierNameLooooooooooooooooooooooooooooooooo
type t = @attr @attrWithSuperLongIdentifierNameLoooooooooooooooooooooooooooooooooooooooooooooong @attrWithSuperLongIdentifierNameLoooooooooooooooooooooooooooooooooooooooooooooong (fooWithSuperLongIdentifierNameLoooooooooooooooooooooooooooooooooooooooooooooong, barWithSuperLongIdentifierNameLoooooooooooooooooooooooooooooooooooooooooooooong, bazWithSuperLongIdentifierNameLoooooooooooooooooooooooooooooooooooooooooooooong) => @attr2 @attrWithSuperLongIdentifierNameLoooooooooooooooooooooooooooooooooooooooooooooong @attrWithSuperLongIdentifierNameLoooooooooooooooooooooooooooooooooooooooooooooong (stringWithSuperLongIdentifierNameLoooooooooooooooooooooooooooooooooooooooooooooong, floatWithSuperLongIdentifierNameLoooooooooooooooooooooooooooooooooooooooooooooong) => unit


external debounce: (int, @meth unit) => unit = "debounce";
external debounce: (int, unit) => unit = "debounce";

external debounce: int => @meth (unit => unit) = "debounce";
external debounce: int => (unit => unit) = "debounce";

external debounce: (int, @meth (unit => unit)) => @meth (unit => unit) = "debounce";
external debounce: (int, (unit => unit)) => (unit => unit) = "debounce";

external debounce: (int, @meth (unit => unit), @meth (unit => unit)) => @meth (unit => unit) = "debounce";
external debounce: (int, (unit => unit), (unit => unit)) => (unit => unit) = "debounce";

external debounce: (int, @meth (unit => unit), @meth ( unit => @meth (unit => unit))) => @meth (unit => unit) = "debounce";
external debounce: (int, (unit => unit), ( unit => (unit => unit))) => (unit => unit) = "debounce";

type returnTyp = (int, int) => @magic float
type returnTyp = (intWithSuperLongIdentifierNameLoooooooooooooooooooooooooooooooooooooooooooooong, intWithSuperLongIdentifierNameLoooooooooooooooooooooooooooooooooooooooooooooong) => @magic float
Expand Down
15 changes: 5 additions & 10 deletions tests/syntax_tests/data/printer/typexpr/expected/arrow.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -174,20 +174,15 @@ type t = @attr
floatWithSuperLongIdentifierNameLoooooooooooooooooooooooooooooooooooooooooooooong,
) => unit

external debounce: (int, @meth unit) => unit = "debounce"
external debounce: (int, unit) => unit = "debounce"

external debounce: int => @meth (unit => unit) = "debounce"
external debounce: int => unit => unit = "debounce"

external debounce: (int, @meth (unit => unit)) => @meth (unit => unit) = "debounce"
external debounce: (int, unit => unit) => unit => unit = "debounce"

external debounce: (int, @meth (unit => unit), @meth (unit => unit)) => @meth (unit => unit) =
"debounce"
external debounce: (int, unit => unit, unit => unit) => unit => unit = "debounce"

external debounce: (
int,
@meth (unit => unit),
@meth (unit => @meth (unit => unit)),
) => @meth (unit => unit) = "debounce"
external debounce: (int, unit => unit, unit => unit => unit) => unit => unit = "debounce"

type returnTyp = (int, int) => @magic float
type returnTyp = (
Expand Down
3 changes: 1 addition & 2 deletions tests/tests/src/meth_annotation.res
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// The @meth annotation is for backwards compatibility. It just makes the type uncurried.
type person = {@meth "say": (string, string) => unit}
type person = {"say": (string, string) => unit}

@val external john: person = "john"

Expand Down
2 changes: 1 addition & 1 deletion tests/tests/src/reasonReact.res
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ and oldNewSelf<'state, 'retainedProps, 'action> = {
type rec jsComponentThis<'state, 'props, 'retainedProps, 'action> = {
"state": totalState<'state, 'retainedProps, 'action>,
"props": {"reasonProps": 'props},
"setState": @meth (
"setState": (
(
totalState<'state, 'retainedProps, 'action>,
'props,
Expand Down