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

Add native function declarations for all relevant Test contract functions #2823

Closed

Conversation

m-Peter
Copy link
Contributor

@m-Peter m-Peter commented Sep 28, 2023

Closes #2822

Description

With the introduction of #2821, we can now declare native functions inside the Test contract, and remove the workaround that used CompositeType.ResolveMembers().


  • Targeted PR against master branch
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work
  • Code follows the standards mentioned here
  • Updated relevant documentation
  • Re-reviewed Files changed in the Github PR explorer
  • Added appropriate labels

@m-Peter
Copy link
Contributor Author

m-Peter commented Sep 28, 2023

I am still getting some checking errors for native function declarations with type parameters, e.g.:

panic: Checking failed:
error: cannot find type in this scope: `T`
   --> Test:445:50

The relevant function declaration is:

/// Creates a matcher with a test function.
/// The test function is of type '((T): Bool)',
/// where 'T' is bound to 'AnyStruct'.
///
access(all)
native fun newMatcher<T: AnyStruct>(_ test: ((T): Bool)): Test.Matcher {}

To my knowledge, I have updated all the relevant parser.Config & sema.Config usages:

parser.Config{
	NativeModifierEnabled: true,
	TypeParametersEnabled: true,
}

&sema.Config{
	BaseValueActivation:     activation,
	AccessCheckMode:         sema.AccessCheckModeStrict,
	AllowNativeDeclarations: true,
}

What could be the root cause of this checking error? 🤔

@SupunS SupunS self-assigned this Sep 28, 2023
@m-Peter m-Peter force-pushed the test-contract-add-native-functions branch from b290058 to 4f89232 Compare October 6, 2023 09:08
@SupunS
Copy link
Member

SupunS commented Oct 11, 2023

Can you maybe rebase the PR on top of #2850, and see if this is now solved?

@m-Peter m-Peter force-pushed the test-contract-add-native-functions branch from 4f89232 to 6eb4de7 Compare October 12, 2023 06:46
@m-Peter
Copy link
Contributor Author

m-Peter commented Oct 12, 2023

Hey @SupunS,

I have rebased on top of master, and indeed the checking error regarding type parameters is solved. However, I hit another roadblock in this commit 6eb4de7. Basically, we have two functions with arity (Test.assert & Test.fail):

// `message` parameter is optional
Arity: &sema.Arity{Min: 1, Max: 2},

Which is not possible to somehow define with native declarations. Any suggestions on how to work around this? Maybe change the function interface?
Related discord thread: https://discord.com/channels/613813861610684416/1159499730573860895/1159806153862172712

@m-Peter
Copy link
Contributor Author

m-Peter commented Nov 8, 2023

Closing this in favor of #2926

@m-Peter m-Peter closed this Nov 8, 2023
@m-Peter m-Peter deleted the test-contract-add-native-functions branch January 12, 2024 11:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Define native function of Test contract in Cadence
2 participants