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

Unrecognized return #435

Open
andreyvdl opened this issue Sep 17, 2023 · 4 comments
Open

Unrecognized return #435

andreyvdl opened this issue Sep 17, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@andreyvdl
Copy link

Describe the bug
Can't recognize return line on a simple main.

Erroneous code

#include <stdio.h>

int     main(void)
{
        struct
        {
                int x;
        }       test;

        test.x = 42;
        printf("%d\n", test.x);
        return (0);
}

Additional infos

  • OS: openSUSE Tumbleweed version 20230915 on Windows 11 x86_64 (Linux 5.15.90.1-microsoft-standard-WSL2 x86_64 x86_64 x86_64 GNU/Linux)
  • python3 --version: Python 3.11.5
  • norminette -v: norminette 3.3.54

Additional context
I was testing if the norm detects anonymous structs as norm error, but it can't recognize the return line.
image

@NiumXp
Copy link
Contributor

NiumXp commented Sep 17, 2023

This is a known bug, you can see the same behavior in #322 (closed), IsDeclaration is greedy when """parsing""" the tokens.

If you use -dd flag, you can see what I'm saying about IsDeclaration:

[...]
test.c - IsDeclaration In "Function" from "GlobalScope" line 5":
                <SPACE> <SPACE> <SPACE> <SPACE> <SPACE> <SPACE> <SPACE> <SPACE> <STRUCT> <NEWLINE>
                <SPACE> <SPACE> <SPACE> <SPACE> <SPACE> <SPACE> <SPACE> <SPACE> <LBRACE> <NEWLINE>
                <SPACE> <SPACE> <SPACE> <SPACE> <SPACE> <SPACE> <SPACE> <SPACE> <SPACE> <SPACE> <SPACE> <SPACE> <SPACE> <SPACE> <SPACE> <SPACE> <INT> <SPACE> <IDENTIFIER=x> <SEMI_COLON> <NEWLINE>
test.c - IsBlockEnd In "Function" from "GlobalScope" line 8":
                <SPACE> <SPACE> <SPACE> <SPACE> <SPACE> <SPACE> <SPACE> <SPACE> <RBRACE> <SPACE> <SPACE> <SPACE> <SPACE> <SPACE> <SPACE> <SPACE> 
test.c - IsVarDeclaration In "GlobalScope" from "None" line 8":
                <IDENTIFIER=test> <SEMI_COLON> 
[An empty line in line 8? wat]
test.c - IsEmptyLine In "GlobalScope" from "None" line 8":
                <NEWLINE>
test.c - IsEmptyLine In "GlobalScope" from "None" line 9":
                <NEWLINE>
test.c - IsAssignation In "GlobalScope" from "None" line 10":
                <SPACE> <SPACE> <SPACE> <SPACE> <SPACE> <SPACE> <SPACE> <SPACE> <IDENTIFIER=test> <DOT> <IDENTIFIER=x> <SPACE> <ASSIGN> <SPACE> <CONSTANT=42> <SEMI_COLON> <NEWLINE>
[...]

Note that the struct you wrote is represented by IsDeclaration, IsBlockEnd and IsVarDeclaration. When norminette sees an IsBlockEnd, it unwraps the scope, this means that after declaring the struct, norminette understands it to be in the global scope and because of this, IsExpressionStatement (return) is not reached (since returns can only appears in a Function or a ControlStructure scope), resulting in the error.

When I first saw this bug (in the issue I mentioned), I noticed another one regarding scopes (softly rewriting the fragmented CheckSpacing), and looking at some project repositories like minishell and web server, I noticed that these two bugs (note that when trying to solve one of them we would probably be forced by the code to solve the other together) cannot be fixed without breaking several tests and projects already written.

@matthieu42Network
Copy link
Contributor

matthieu42Network commented Sep 19, 2023

Hello, after some discussion with the pedago, with thought it should not be allowed to declare struct inside function.
And in the PDF it is mentioned that: You cannot declare a structure in a .c file.

@matthieu42Network matthieu42Network added the bug Something isn't working label Sep 19, 2023
@andreyvdl
Copy link
Author

if we should not declare a struct in .c files, then this is also wrong:

struct s_test {
	int	a;
};

int	main(void)
{
	struct s_test	test;

	test.a = 42;
	return (test.a);
}

I tested this on the campus PC so i will repass the specs

OS: Ubuntu 20.04.5 LTS
python3 --version: Python 3.8.10
norminette -v: norminette 3.3.52

but the norminette doesn't detect:
Screenshot from 2023-09-19 15-18-26

@matthieu42Network
Copy link
Contributor

Seems like this rules were never implemented in the norminette :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants