Skip to content

Commit

Permalink
fix(fast_check): remove array elements in internal impl for spread ex…
Browse files Browse the repository at this point in the history
…prs (#559)
  • Loading branch information
dsherret authored Jan 7, 2025
1 parent fa4b4bf commit ec02a2c
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/fast_check/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1467,6 +1467,20 @@ impl<'a> FastCheckTransformer<'a> {
self.mark_diagnostic(FastCheckDiagnostic::MissingExplicitType {
range: self.source_range_to_range(p.range()),
})?;
} else {
match &mut *p.arg {
Pat::Array(array_pat) => {
array_pat.elems.clear();
}
Pat::Object(object_pat) => {
object_pat.props.clear();
}
Pat::Rest(_) | Pat::Expr(_) | Pat::Assign(_) => {
// shouldn't happen, so just make it an empty object
p.arg = Box::new(Pat::Expr(empty_obj_lit_expr()));
}
Pat::Invalid(_) | Pat::Ident(_) => {}
};
}
}
Pat::Array(p) => {
Expand Down
119 changes: 119 additions & 0 deletions tests/specs/graph/fast_check/issue_27575.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# 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/add.ts
export const add = (a:bigint,b:bigint):bigint => { return a + b};

# https://jsr.io/@scope/a/1.0.0/mod.ts
import { add } from "./add.ts";

export const useFn = (
...[a, b, fn = add]: [bigint, bigint, (a: bigint, b: bigint) => bigint]
): bigint => {
return fn(a, b);
}

export function useFn2(...[a, b, fn = add]: [bigint, bigint, (a: bigint, b: bigint) => bigint]): bigint {
return fn(a, b);
}

export function useFn3(...{ a }: { a: number, b: number }): bigint {
return fn(a, b);
}

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

# output
{
"roots": [
"file:///mod.ts"
],
"modules": [
{
"kind": "esm",
"dependencies": [
{
"specifier": "jsr:@scope/a",
"code": {
"specifier": "jsr:@scope/a",
"resolutionMode": "import",
"span": {
"start": {
"line": 0,
"character": 7
},
"end": {
"line": 0,
"character": 21
}
}
}
}
],
"size": 22,
"mediaType": "TypeScript",
"specifier": "file:///mod.ts"
},
{
"kind": "esm",
"size": 66,
"mediaType": "TypeScript",
"specifier": "https://jsr.io/@scope/a/1.0.0/add.ts"
},
{
"kind": "esm",
"dependencies": [
{
"specifier": "./add.ts",
"code": {
"specifier": "https://jsr.io/@scope/a/1.0.0/add.ts",
"resolutionMode": "import",
"span": {
"start": {
"line": 0,
"character": 20
},
"end": {
"line": 0,
"character": 30
}
}
}
}
],
"size": 393,
"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/[email protected]"
}
}

Fast check https://jsr.io/@scope/a/1.0.0/mod.ts:
{}
export const useFn = (...[]: [bigint, bigint, (a: bigint, b: bigint) => bigint]): bigint =>({} as never);
export function useFn2(...[]: [bigint, bigint, (a: bigint, b: bigint) => bigint]): bigint {
return {} as never;
}
export function useFn3(...{}: {
a: number;
b: number;
}): bigint {
return {} as never;
}
--- DTS ---
export declare const useFn: (...[]: [bigint, bigint, (a: bigint, b: bigint) => bigint]) => bigint;
export declare function useFn2(...[]: [bigint, bigint, (a: bigint, b: bigint) => bigint]): bigint;
export declare function useFn3(...{}: {
a: number;
b: number;
}): bigint;

0 comments on commit ec02a2c

Please sign in to comment.