-
Notifications
You must be signed in to change notification settings - Fork 365
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
assume type is address if type is unknown #291
Conversation
instead of throwing an exception, this change will assume unknown types are addresses and return them as such. this is a lot more graceful than killing the whole compile process because some libraries had unknown types.
@Killerbyte can you please provide contract code of a minimal reproduction of this issue? |
here is the contract which my code fails on: here is the buidler artifact input file: https://gist.github.com/KillerByte/38ddb41e29295464541e0ece13cd8d3f if I try building the buidler input file with:
I get output
|
@quezak let me know if it is still necessary to isolate the problem further. |
@Killerbyte I think your proposed solution is too broad -- we don't know what else the solidity compiler might put in the I'd update it to return @krzkaczor what do you think? |
@quezak part of my concern that I think we should explore in this PR is whether or not it is correct to throw an exception and die, or give a "best guess" with a warning, since when I use typechain with buidler, a single failure throws off the whole compilation process, and since I don't control these libraries, it causes problems. |
@Killerbyte while this may be a good idea in some cases, always guessing IMHO we should apply the fix I mentioned when we have enough hints the type is an address, but keep throwing an error if we really don't know the type. An additional advantage is that someone will report it and we can fix the issue 😃 (and we try to accept simple PRs quickly, so this shouldn't be an issue for developement -- but if you're in a hurry, you can always use patch-package until we do) If we really wanted to add some workarounds to not fail generation here, the proper way may be to return a special |
I basically agree with everything that @quezak said. We already have some similar heuristics in TC codebase. I hate it but what can you do 🤷 To sum up:
@Killerbyte let us know if you want to work on this. We def need tests for this. (2) seems like a breaking change for TypeChain core and all targets unfortunately so I would love to release it together with a fix for #234 |
sure I will work on it. expect result within a few days. |
return "any" type in typescript when unable to parse
@krzkaczor let me know. not sure why circleci is complaining though. |
@Killerbyte circleci complaints are right 😄 The generated |
@@ -28,6 +31,9 @@ export type TupleType = { type: 'tuple'; components: EvmSymbol[]; originalType: | |||
// used only for output types | |||
export type VoidType = { type: 'void' } | |||
|
|||
// used when type cannot be detected | |||
export type UnknownType = { type: 'any'; originalType: string } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to keep it consistent: IMO it should be:
export type UnknownType = { type: 'unknown'; originalType: string }
@krzkaczor sorry for the commit spam, was having some computer issues. I'm concerned that additional tests may be necessary for the target libraries to verify that the use of |
@Killerbyte it looks good, I left 1 comm. As for testing it, it would be best if you would add a contract that generates a need to return |
If our goal is to only include this "Unknown" type for ABI inputs/outputs that are not understood by the |
Ahh sorry, you're right it shouldn't be possible to construct such a contract. In that case, I think this part is fine. I have a high level of certainty for the code generation part as it's typesafe and basically, compiler forced you to tweak types everywhere. So two last things:
|
also fix formatting
Thanks for your hard work @Killerbyte! This looks great! I want to merge a little bit more things before cutting a release so I'll let you know when this is released. |
When given a abi definition with a type defined as such:
typechain fails to recognize the
IConfigurableRightsPool
type. I would not be so bothered by this normally, but when it fails, it stops the whole compilation.instead of throwing an exception, this change will assume unknown types are addresses and return them as such.
this is a lot more graceful than killing the whole compile process because some libraries that I don't even use in TS had unknown types.
im not sure if there is a better way to approach this particular issue, but if I am missing something please suggest. For example, still return type address, but throw a warning instead of an error?