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 Struct issues #567

Merged
merged 10 commits into from
Nov 28, 2022
Merged

Fix Struct issues #567

merged 10 commits into from
Nov 28, 2022

Conversation

mitschabaude
Copy link
Member

@mitschabaude mitschabaude commented Nov 16, 2022

This fixes type inference in the following code example:

class A extends Struct({a: Field}) {
  print() {
    console.log(this.a.toString());
  }
}

class B extends Struct({a: A, b: Bool}) {
  print() {
    this.a.print(); // FIXED!
  }
}

The type inference is changed in a way that it tries to not affect cases where inferring a class type already worked (e.g., CircuitValues like UInt32)

EDIT: this PR now is about fixing more issues with Struct that came up

@mitschabaude mitschabaude changed the title Fix nested Struct type inference Fix Struct issues (type inference, APIs not accepting Structs with methods, fromJSON) Nov 28, 2022
@mitschabaude mitschabaude changed the title Fix Struct issues (type inference, APIs not accepting Structs with methods, fromJSON) Fix Struct issues (type inference, APIs not accepting Structs, fromJSON) Nov 28, 2022
@mitschabaude mitschabaude changed the title Fix Struct issues (type inference, APIs not accepting Structs, fromJSON) Fix Struct issues Nov 28, 2022
Copy link
Member

@Trivo25 Trivo25 left a comment

Choose a reason for hiding this comment

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

lgtm, just left a small comment

src/lib/circuit_value.test.ts Show resolved Hide resolved
@mitschabaude mitschabaude merged commit 61fc19e into main Nov 28, 2022
@mitschabaude mitschabaude deleted the fix/struct-infer-nested branch November 28, 2022 16:28
@Comdex
Copy link
Contributor

Comdex commented Nov 29, 2022

@mitschabaude Hey, can you export these two types for external use? This allows developers to use these types to support various custom Structs as parameters of generic methods.

type FlexibleProvable<T> = Provable<T> | Struct<T>;
type FlexibleProvablePure<T> = ProvablePure<T> | StructPure<T>;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants