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

WIP: Show a better error on duplicate command #38

Merged

Conversation

rburchell
Copy link
Contributor

Usecase:

foo:
    echo "hello"

foo:
    echo "world"

Gives: run: Duplicate command: foo defined on line 4 -- originally defined on line 0

version:
    echo "hello"

Gives: run: Duplicate command: version defined on line 0 -- this command is built-in

Marked as WIP because the first line is showing up with line 0. I'm not sure if this is a bug in the parser/tokenizer, or if I'm missing something. It seems strange that the second definition is correctly showing up as line 4...

main.go Show resolved Hide resolved
@TekWizely
Copy link
Owner

Hey found the bug and have a PR up here:

Feel free to give it a quick once over.

Thanks!

-TW

@rburchell
Copy link
Contributor Author

Okay, so with the line number fixed... I'm actually not sure if there's anything left to do here, I did do this in a bit of a rush, but now I look at it again, I'm not sure there's much missing. Maybe some tests - but I'm not sure what the right place for those would be? Anything you'd like changed?

@TekWizely
Copy link
Owner

I've updated go.mod to use the latest version of the go-parsing libs which includes the fix for the line0 bug.
Please re-base your branch and see if it helps !

Comment on lines +673 to 675
startLine := -1
var t token.Token
var name string
Copy link
Owner

Choose a reason for hiding this comment

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

Are we gaining anything with the init to -1 ( vs var startLine int ) ?

For symmetry, I would likely arrange them as:

var name string
var startLine int
var t token.Token

With t being short-lived, have it assigned closer to the block its used in.

Have name and startLine defined in the order they generally appear (assignment and return)

Lastly, line may be a sufficient name

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(sorry, I haven't had a chance to look at updating this yet)

Are we gaining anything with the init to -1 ( vs var startLine int ) ?

The main gain in my mind is that -1 is obviously invalid, whereas 0 is potentially correct (logic depending :))

But sure, I can change it to be a 0 default.

Copy link
Owner

Choose a reason for hiding this comment

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

The main gain in my mind is that -1 is obviously invalid

I get that as a concept and generally agree, but, because the value is aways assigned from t.Line(), is there any way for that default value to get returned?

That's why I didn't think we were gaining anything ...

@TekWizely
Copy link
Owner

I'm going to merge this. The changes that I want are small and I can make them in post.

Thanks for this PR - I suspect that having the cmd line number handy will prove even more useful in the future !

-TW

@TekWizely TekWizely merged commit 133b1aa into TekWizely:master Sep 17, 2021
@rburchell
Copy link
Contributor Author

Thanks, sorry for not being able to follow up. I've had a busy week.

@rburchell rburchell deleted the improve-duplicate-command-error branch September 20, 2021 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants