From 668175851bdaaa69d50a8e43c047eba7eddc778f Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Wed, 16 Apr 2025 15:25:05 +0200 Subject: [PATCH] Improved error message #2084 --- .github/workflows/main.yml | 123 ------------------- src/compiler/parse_stmt.c | 12 ++ test/test_suite/statements/if_missing_and.c3 | 6 + 3 files changed, 18 insertions(+), 123 deletions(-) create mode 100644 test/test_suite/statements/if_missing_and.c3 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 431141d89..de7512e7b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -401,129 +401,6 @@ jobs: name: c3-linux-${{matrix.build_type}} path: c3-linux-${{matrix.build_type}}.tar.gz - build-linux-ubuntu20: - runs-on: ubuntu-20.04 - strategy: - # Don't abort runners if a single one fails - fail-fast: false - matrix: - build_type: [Release, Debug] - llvm_version: [17, 18, 19, 20] - steps: - - uses: actions/checkout@v4 - - name: Install common deps - run: | - sudo apt-get install zlib1g zlib1g-dev python3 ninja-build curl - - - name: Install Clang ${{matrix.llvm_version}} - run: | - wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - - if [[ "${{matrix.llvm_version}}" < "${{env.LLVM_DEV_VERSION}}" ]]; then - sudo add-apt-repository "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-${{matrix.llvm_version}} main" - else - sudo add-apt-repository "deb http://apt.llvm.org/focal/ llvm-toolchain-focal main" - fi - sudo apt-get update - sudo apt-get install -y clang-${{matrix.llvm_version}} llvm-${{matrix.llvm_version}} llvm-${{matrix.llvm_version}}-dev lld-${{matrix.llvm_version}} liblld-${{matrix.llvm_version}}-dev - sudo apt-get install -y libmlir-${{matrix.llvm_version}} libmlir-${{matrix.llvm_version}}-dev mlir-${{matrix.llvm_version}}-tools - sudo apt-get install -y libpolly-${{matrix.llvm_version}}-dev - - name: CMake Old - if: matrix.llvm_version < 18 || matrix.llvm_version == env.LLVM_DEV_VERSION - run: | - cmake -B build \ - -G Ninja \ - -DCMAKE_BUILD_TYPE=${{matrix.build_type}} \ - -DCMAKE_C_COMPILER=clang-${{matrix.llvm_version}} \ - -DCMAKE_CXX_COMPILER=clang++-${{matrix.llvm_version}} \ - -DCMAKE_LINKER=lld-link-${{matrix.llvm_version}} \ - -DCMAKE_OBJCOPY=llvm-objcopy-${{matrix.llvm_version}} \ - -DCMAKE_STRIP=llvm-strip-${{matrix.llvm_version}} \ - -DCMAKE_DLLTOOL=llvm-dlltool-${{matrix.llvm_version}} \ - -DC3_LLVM_VERSION=${{matrix.llvm_version}} - cmake --build build - - name: CMake - if: matrix.llvm_version >= 18 && matrix.llvm_version != env.LLVM_DEV_VERSION - run: | - cmake -B build \ - -G Ninja \ - -DCMAKE_BUILD_TYPE=${{matrix.build_type}} \ - -DCMAKE_C_COMPILER=clang-${{matrix.llvm_version}} \ - -DCMAKE_CXX_COMPILER=clang++-${{matrix.llvm_version}} \ - -DCMAKE_LINKER=lld-link-${{matrix.llvm_version}} \ - -DCMAKE_OBJCOPY=llvm-objcopy-${{matrix.llvm_version}} \ - -DCMAKE_STRIP=llvm-strip-${{matrix.llvm_version}} \ - -DCMAKE_DLLTOOL=llvm-dlltool-${{matrix.llvm_version}} \ - -DC3_LLVM_VERSION=${{matrix.llvm_version}}.1 - cmake --build build - - name: Compile and run some examples - run: | - cd resources - ../build/c3c compile examples/gameoflife.c3 - ../build/c3c compile-only examples/levenshtein.c3 - ../build/c3c compile-only examples/map.c3 - ../build/c3c compile examples/mandelbrot.c3 - ../build/c3c compile examples/plus_minus.c3 - ../build/c3c compile examples/spectralnorm.c3 - ../build/c3c compile examples/swap.c3 - ../build/c3c compile examples/contextfree/guess_number.c3 - ../build/c3c compile-run examples/hash.c3 - ../build/c3c compile-run examples/nbodies.c3 - ../build/c3c compile-run examples/contextfree/boolerr.c3 - ../build/c3c compile-run examples/contextfree/dynscope.c3 - ../build/c3c compile-run examples/contextfree/multi.c3 - ../build/c3c compile-run examples/contextfree/cleanup.c3 - ../build/c3c compile-run examples/hello_world_many.c3 - ../build/c3c compile-run examples/time.c3 - ../build/c3c compile-run examples/fannkuch-redux.c3 - ../build/c3c compile-run examples/load_world.c3 - ../build/c3c compile-run examples/base64.c3 - ../build/c3c compile-run examples/binarydigits.c3 - ../build/c3c compile-run examples/brainfk.c3 - ../build/c3c compile-run examples/factorial_macro.c3 - ../build/c3c compile-run examples/fasta.c3 - ../build/c3c compile-run examples/process.c3 - ../build/c3c compile-run --linker=builtin linux_stack.c3 - ../build/c3c compile-run linux_stack.c3 - ../build/c3c compile-run examples/args.c3 -- foo -bar "baz baz" - - - name: Compile run unit tests - run: | - cd test - ../build/c3c compile-test unit --sanitize=address - - - name: Build testproject - run: | - cd resources/testproject - ../../build/c3c run -vvv --trust=full - - - name: Build testproject direct linker - run: | - cd resources/testproject - ../../build/c3c run -vvv --linker=builtin --trust=full - - - name: run compiler tests - run: | - cd test - ../build/c3c compile-run -O1 src/test_suite_runner.c3 -- ../build/c3c test_suite/ - - - name: bundle_output - if: matrix.llvm_version == env.LLVM_RELEASE_VERSION_UBUNTU20 - run: | - mkdir c3 - cp -r lib c3 - cp README.md c3 - cp releasenotes.md c3 - cp msvc_build_libraries.py c3 - cp build/c3c c3 - tar czf c3-ubuntu-20-${{matrix.build_type}}.tar.gz c3 - - - name: upload artifacts - if: matrix.llvm_version == env.LLVM_RELEASE_VERSION_UBUNTU20 - uses: actions/upload-artifact@v4 - with: - name: c3-ubuntu-20-${{matrix.build_type}} - path: c3-ubuntu-20-${{matrix.build_type}}.tar.gz - build-with-docker: runs-on: ubuntu-22.04 strategy: diff --git a/src/compiler/parse_stmt.c b/src/compiler/parse_stmt.c index f431a62d7..988206203 100644 --- a/src/compiler/parse_stmt.c +++ b/src/compiler/parse_stmt.c @@ -613,6 +613,18 @@ static inline Ast* parse_if_stmt(ParseContext *c) CONSUME_OR_RET(TOKEN_LPAREN, poisoned_ast); ASSIGN_EXPRID_OR_RET(if_ast->if_stmt.cond, parse_cond(c), poisoned_ast); unsigned row = c->span.row; + if (!tok_is(c, TOKEN_RPAREN)) + { + switch (c->tok) + { + case TOKEN_IDENT: + case TOKEN_CONST: + PRINT_ERROR_HERE("Finding an identifier here was surprising - did you forget '||' / '&&' or the ending ')'?"); + return poisoned_ast; + default: + break; + } + } CONSUME_OR_RET(TOKEN_RPAREN, poisoned_ast); unsigned next_row = c->span.row; diff --git a/test/test_suite/statements/if_missing_and.c3 b/test/test_suite/statements/if_missing_and.c3 new file mode 100644 index 000000000..7d541d254 --- /dev/null +++ b/test/test_suite/statements/if_missing_and.c3 @@ -0,0 +1,6 @@ +module test; + +fn int main() +{ + if (option.long_name != "" arg.starts_with("--")) // #error: '||' / '&&' or the ending ')' +} \ No newline at end of file