Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix fatal error for external with @as#7978

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
cknitt merged 4 commits intomasterfromfix-external-as
Oct 23, 2025
Merged

Conversation

@cknitt
Copy link
Member

@cknittcknitt commentedOct 22, 2025
edited
Loading

Fixes#7972

When the external function has a single arg that gets a fixed value via@as(json, all that's left is a actually constant, see test.

in
let fn_type=Ast_helper.Typ.arrows~loc args result_typein
(build_uncurried_type~arity:(List.length args)fn_type,
( fn_type,
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

build_uncurried_type was trying to set a function type even if no args were left.
But the function type with the correct arity is already set byAst_helper.Typ.arrows anyway when required.

@pkg-pr-new
Copy link

pkg-pr-newbot commentedOct 22, 2025
edited
Loading

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript-lang/rescript@7978

@rescript/darwin-arm64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/darwin-arm64@7978

@rescript/darwin-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/darwin-x64@7978

@rescript/linux-arm64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/linux-arm64@7978

@rescript/linux-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/linux-x64@7978

@rescript/runtime

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/runtime@7978

@rescript/win32-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/win32-x64@7978

commit:1badbec

@cknitt
Copy link
MemberAuthor

When the external function has a single arg that gets a fixed value via@as(json, all that's left is a actually constant, see test.

Or do we want/need to add an "artificial"unit argument there to keep it a function?

Copy link
Collaborator

@cristianoccristianoc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

The fact that the function without any args gets called automatically seems pretty weird to me.
I would have expected this would not be allowed.
But if that's what one wants, OK.

Notice the risk is this change affects other cases unrelated to this. But I assume some though went into removing build_uncurried_type as mentioned in the comment.

@cknitt
Copy link
MemberAuthor

The fact that the function without any args gets called automatically seems pretty weird to me.
I would have expected this would not be allowed.
But if that's what one wants, OK.

Not sure if that's what one wants. 🙂 I can look into introducing an "artificial" unit arg.

Notice the risk is this change affects other cases unrelated to this. But I assume some though went into removing build_uncurried_type as mentioned in the comment.

build_uncurried_type only sets the same arity thatarrows already set before.
(Unless fn_type is not actually a function, in which case it crashes.)

@cknitt
Copy link
MemberAuthor

@cristianoc now adding a synthetic unit argument, please have another look.

@cknitt
Copy link
MemberAuthor

@codex review

Copy link

@chatgpt-codex-connectorchatgpt-codex-connectorbot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +1029 to 1031
(Ast_helper.Typ.arrows~loc args result_type,
External_ffi_types.ffi_bs arg_type_specs return_wrapper ffi,
unused_attrs,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

P1 Badge Preserve uncurried arity when rebuilding external type

Previously this code rebuilt the return type withbuild_uncurried_type ~arity:(List.length args) so externals declared with an uncurried arrow retained theirarity metadata. After the change it returnsAst_helper.Typ.arrows directly and thebuild_uncurried_type wrapper is never applied in the non-object path, so externals such asexternal add: (int, int) => int are now typed asint -> int -> int. Calls written with uncurried syntax (add(1, 2)) will start raisingApply_non_function/arity mismatches during type checking because the arity flag is gone. The new code should still applybuild_uncurried_type to the reconstructed arrow to keep uncurried externals working.

Useful? React with 👍 / 👎.

cristianoc reacted with thumbs down emoji
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@codex ButAst_helper.Typ.arrows does already set the arity for the outer function toList.length args.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Definitely not true,external add: (int, int) => int still works correctly.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

How comes codex runs now? That changed?
It used to get stuck trying to install ocaml.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think it didn't actually run anything, it just reviews the code.

Copy link
Collaborator

@cristianoccristianoc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Looks great.
Btw conceptually this just builds a function of arity 0 (the same way as arity 2 with unit type). I thought we already had helpers that take arity as arg and support 0.
But not 100% sure.

@cknittcknitt merged commit3565257 intomasterOct 23, 2025
25 checks passed
@cknittcknitt deleted the fix-external-as branchOctober 23, 2025 13:26
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@chatgpt-codex-connectorchatgpt-codex-connector[bot]chatgpt-codex-connector[bot] left review comments

@cristianoccristianoccristianoc approved these changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

@as in extern can crash compiler

3 participants

@cknitt@cristianoc

[8]ページ先頭

©2009-2025 Movatter.jp