-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Bug fix: don't clobber repl context variables when setting up repl context #5573
Conversation
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.
Nicely done @eggplantzzz ! I verified that:
- If contract name doesn't conflict, hydrate to repl.
- If conflict, contract available via
artifacts.require
Which I think is very sensible! We definitely need to document this though.
Two more things:
- We prob want tests for this? Though I think that can come later and this PR shouldn't be held back.
- Release: I consider this breaking because there may be users relying on the current behavior to overwrite node's built-in objects.
So I found an issue with the current implementation here that needs to be fixed. Currently it won't clobber names in the context the first call to What we really need to do is make a note of all name conflicts on the first provision. On subsequent calls to |
an update is necessary since an issue has been found with the current implementation
3f25acf
to
25b17da
Compare
I tested it with Buffer.sol with Buffer contract and compilation succeeds and
And the truffle prompt does not return. I need to hit return key to see the truffle prompt again:
|
Hmmm @dongmingh you shouldn't be getting warnings for things like MetaCoin and ConvertLib. Edit: I figured out what you did :) |
@eggplantzzz let me know if need me to show you how I saw this. |
8a5250c
to
5fb73ea
Compare
Thanks @dongmingh, I found a bug with how contracts are detected and fixed it. You should no longer be getting conflicts for things like MetaCoin. However, the prompt still does not appear when the warning is present. |
Ok I also caused the prompt to display after provisioning which will cause the warning to display before the prompt. So the other bug you found @dongmingh should be fixed now. |
I retest it and no longer see conflict contracts like MetaCoin. Also the truffle prompt displays as expected. Thanks. |
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.
Thanks, @eggplantzzz, this looks better! I left a few nits and requesting changes for testing.
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.
Had a scenario question.
@clifoo, what if we consider clobbering a bug, so this can be a patch instead of breaking? What do you think? |
I believe that's the conclusion @eggplantzzz mentioned earlier, though I'm not fully convinced. This reminds me of the recent integer/string conversion change pushed to python as a patch release (short video for context). Yes it was a bug, they fixed it, yet it broke things anyway. Similarly, this is bug fix and it's breaking. (My |
If we consider this a breaking change we can't get it in until v6. Originally through discussion with @gnidan we decided this was a bug fix. We can revisit and discuss this again. |
050b49f
to
70d58a0
Compare
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 verified this works, which is really cool. I left some minor nits, and requesting a rework of the display conflict alert logic.
…at not to overwrite later
…ser will end up on the prompt
…h Node's native stuff
70d58a0
to
1893289
Compare
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 kept coming back to this because something was bugging me. Unless I'm missing something, this logic can be simplified if we track two pieces of state:
knownCollisionsSoFar
newlyDiscoveredCollisions
fn recordNameConflicts
would add update thenewlyDiscoveredCollisions
container IFF new abstraction isn't inknownCollisionsSoFar
fn resetContractsInConsoleContext
would:- load the abstraction in context if the name isn't in both
newlyDiscoveredCollisions
andknownCollisionsSoFar
- alert user if
newlyDiscoveredCollisions
has items - move
newlyDiscoveredCollisions
toknownCollisionsSoFar
- reset
newlyDiscoveredCollisions
- load the abstraction in context if the name isn't in both
Of course, please correct me if I missed a key piece of the logic.
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.
This is much easier to follow! I left a stylistic comment, feel free to ignore; and a change request to use Set.keys()
instead of Set.entries()
in the for of
loop.
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.
LGTM. Thanks, @eggplantzzz!
As mentioned in #3329, if a user has a contract name that conflicts with one of Node's native objects (such as
Buffer
) then it will overwrite that object. This could cause things to break. In order to fix this, this PR provides an implementation where Truffle will not overwrite objects found in the context the first time it loads the repl and sets up the environment. Theprovision
method is where these things are set up, and on subsequent calls toprovision
it will overwrite things it finds in the repl context as it will need to update contracts that have changed etc.