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

fix(fast_check): properly handle rest parameters in overloads #432

Merged
merged 3 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
42 changes: 31 additions & 11 deletions src/fast_check/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -911,18 +911,38 @@ impl<'a> FastCheckTransformer<'a> {
}
if is_overload {
for (i, param) in n.params.iter_mut().enumerate() {
*param = Param {
span: DUMMY_SP,
decorators: Vec::new(),
pat: Pat::Ident(BindingIdent {
id: Ident {
if param.pat.is_rest() {
*param = Param {
span: DUMMY_SP,
decorators: Vec::new(),
pat: Pat::Rest(RestPat {
span: DUMMY_SP,
sym: format!("param{}", i).into(),
optional: true,
},
type_ann: Some(any_type_ann()),
}),
};
dot3_token: DUMMY_SP,
type_ann: Some(any_type_ann()),
arg: Box::new(Pat::Ident(BindingIdent {
id: Ident {
span: DUMMY_SP,
sym: format!("param{}", i).into(),
optional: true,
},
type_ann: None,
})),
}),
};
} else {
*param = Param {
span: DUMMY_SP,
decorators: Vec::new(),
pat: Pat::Ident(BindingIdent {
id: Ident {
span: DUMMY_SP,
sym: format!("param{}", i).into(),
optional: true,
},
type_ann: Some(any_type_ann()),
}),
};
}
}
n.return_type = Some(any_type_ann());
}
Expand Down
89 changes: 89 additions & 0 deletions tests/specs/graph/jsr/FastCheck_Overloads.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# https://jsr.io/@scope/a/meta.json
{"versions": { "1.0.0": {} } }

# https://jsr.io/@scope/a/1.0.0_meta.json
{ "exports": { ".": "./mod.ts" } }

# https://jsr.io/@scope/a/1.0.0/mod.ts
export class argsToArray {
argsToArray(..._args: string[]): void;
argsToArray(..._args: number[]): void;
argsToArray(..._args: unknown[]): void {}
}

function overloadSpread(...args: string[]);
function overloadSpread(...args: number[]);
export function overloadSpread(...args: unknown[]) {
return args;
}
lucacasonato marked this conversation as resolved.
Show resolved Hide resolved

# mod.ts
import 'jsr:@scope/a'

# output
{
"roots": [
"file:///mod.ts"
],
"modules": [
{
"kind": "esm",
"dependencies": [
{
"specifier": "jsr:@scope/a",
"code": {
"specifier": "jsr:@scope/a",
"span": {
"start": {
"line": 0,
"character": 7
},
"end": {
"line": 0,
"character": 21
}
}
}
}
],
"size": 22,
"mediaType": "TypeScript",
"specifier": "file:///mod.ts"
},
{
"kind": "esm",
"size": 314,
"mediaType": "TypeScript",
"specifier": "https://jsr.io/@scope/a/1.0.0/mod.ts"
}
],
"redirects": {
"jsr:@scope/a": "https://jsr.io/@scope/a/1.0.0/mod.ts"
},
"packages": {
"@scope/a": "@scope/a@1.0.0"
}
}

Fast check https://jsr.io/@scope/a/1.0.0/mod.ts:
{}
export class argsToArray {
argsToArray(..._args: string[]): void;
argsToArray(..._args: number[]): void;
argsToArray(...param0?: any): any {
return {} as never;
}
}
function overloadSpread(...args: string[]);
function overloadSpread(...args: number[]);
export function overloadSpread(...param0?: any): any {
return {} as never;
}
--- DTS ---
export declare class argsToArray {
argsToArray(..._args: string[]): void;
argsToArray(..._args: number[]): void;
}
declare function overloadSpread(...args: string[]);
declare function overloadSpread(...args: number[]);
export declare function overloadSpread(...param0?: any): any;
lucacasonato marked this conversation as resolved.
Show resolved Hide resolved