Error and stop build a contract that has method name confliction #346
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is to address #121.
The near-sdk-js builds a contract by generate a C file and turns each contract method to a C function, then compile this C file into a wasm file. Therefore, it's possible the contract method name conflicts with the C function name in
builder.c
.Because a contract method name
foo
will generate avoid foo(void)
in the C file, there're totally 4 possible cases of different result will happen. Those are a contract method namefoo
becomes the same as:void foo(void)
inbuilder.c
or it's includeextern void foo(void)
inbuilder.c
or it's includefoo
function with other signature inbuilder.c
or it's include. E.g.:strcpy
extern foo
function with other signature. E.g.:storage_read
.Case 1. doesn't exist as we checked
builder.c
and it's include. Case 2. only has one functionpanic
. If user attempts to define apanic
contract method, it will causeenv.panic()
call that method instead, which causes misleading result. In this PR this becomes an error. In case 3 and 4, theC -> WASM
step C compiler gives error because breaks the C signature. In this PR, it collects the error message, transform it into a user friendly one and inform user to avoid usingfoo
and ends the build.All cases are tested with the CLI in this PR. It reports errors like this:
- case 3&4: