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

Stub generator generates invalid code when named variables conflict with loop variable #52

Open
Andriamanitra opened this issue Apr 20, 2024 · 0 comments
Labels
bug Something isn't working wontfix This will not be worked on

Comments

@Andriamanitra
Copy link
Owner

Describe the bug
Template generator produces invalid code in languages that don't allow shadowing and use a loop variable that is named the same as one of the names in the stub generator. Currently this only affects C++, but as more languages get added some of them will likely have similar issues.

To Reproduce

$ echo 'loopline N i:int' | clash generate-stub cpp --from-file -
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;


int main() {
    for (int i = 0; i < n; i++) {
        int i;
        cin >> i; cin.ignore();
    }

    return 0;
}
$ echo 'loopline N i:int' | clash generate-stub cpp --from-file - | gcc -x c++ -fsyntax-only -
<stdin>: In function ‘int main()’:
<stdin>:10:25: error: ‘n’ was not declared in this scope
<stdin>:11:13: error: redeclaration of ‘int i’
<stdin>:10:14: note: ‘int i’ previously declared here

CodinGame itself suffers from the exact same issue so we don't have plans to fix this on our side either.

@Andriamanitra Andriamanitra added bug Something isn't working wontfix This will not be worked on labels Apr 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

1 participant