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

[Bug] Internal error after redeclaration of variable #462

Closed
3 tasks done
Tracked by #463 ...
Luna-Klatzer opened this issue Jun 7, 2023 · 1 comment · Fixed by #463
Closed
3 tasks done
Tracked by #463 ...

[Bug] Internal error after redeclaration of variable #462

Luna-Klatzer opened this issue Jun 7, 2023 · 1 comment · Fixed by #463
Assignees
Labels
bug Bug or issue in the language or API

Comments

@Luna-Klatzer
Copy link
Member

Is there an existing issue for this?

  • I have searched the existing issues

I am following the documentation's guide

  • I have read the documentation

This issue exists in the latest version

  • I am using the latest version

Current Behavior

Using the following code, the compiler generates an InternalError reporting a failure in the resolution of the internal scope declaration:

var name: str = "Luna";
var age: num = 20;

var name: str = "Luna";
var age: num = 20;

The resulting error:

ERROR Compilation error - Traceback:
File '/home/luna/data/WebstormProjects/Kipper/test.kip', line 3, col 0:
  var name: str = "Luna";
  ^^^^^^^^^^^^^^^^^^^^^^ 
IdentifierError: Redeclaration of variable 'name'. 
FATAL Failed to compile 'test.kip'. 
FATAL Encountered unexpected internal error: 
InternalError: Failed to determine the declaration context for a declaration. Most likely the semantic analysis failed or the property was accessed too early during semantic analysis. - Report this bug to the developer using the traceback!
    at VariableDeclaration.getScopeDeclaration (/home/luna/.local/share/pnpm/global/5/.pnpm/@kipper+core@0.10.1/node_modules/@kipper/core/lib/compiler/ast/nodes/definitions.js:27:19)
    at VariableDeclaration.getScopeDeclaration (/home/luna/.local/share/pnpm/global/5/.pnpm/@kipper+core@0.10.1/node_modules/@kipper/core/lib/compiler/ast/nodes/definitions.js:186:22)
    at VariableDeclaration.<anonymous> (/home/luna/.local/share/pnpm/global/5/.pnpm/@kipper+core@0.10.1/node_modules/@kipper/core/lib/compiler/ast/nodes/definitions.js:227:78)
    at Generator.next (<anonymous>)
    at /home/luna/.local/share/pnpm/global/5/.pnpm/tslib@2.4.1/node_modules/tslib/tslib.js:118:75
    at new Promise (<anonymous>)
    at Object.__awaiter (/home/luna/.local/share/pnpm/global/5/.pnpm/tslib@2.4.1/node_modules/tslib/tslib.js:114:16)
    at VariableDeclaration.primarySemanticTypeChecking (/home/luna/.local/share/pnpm/global/5/.pnpm/@kipper+core@0.10.1/node_modules/@kipper/core/lib/compiler/ast/nodes/definitions.js:218:24)
    at VariableDeclaration.<anonymous> (/home/luna/.local/share/pnpm/global/5/.pnpm/@kipper+core@0.10.1/node_modules/@kipper/core/lib/compiler/ast/analysable-ast-node.js:103:32)
    at Generator.next (<anonymous>)

To simply the reproduction case, you can simply write:

var name: str = "Luna";
var name: str = "Luna";

Expected Behavior

The compiler should only return the redeclaration errors and not the internal error.

Steps To Reproduce

  1. Define a variable with a value assigned of any type.
  2. Create another variable definition with a value of the same type.
  3. For example:
    var name: str = "Luna";
    var name: str = "Luna";

Environment

  • Kipper: 0.10.1
  • Environment: Node.js v18.15.0
  • Operating System: Arch Linux with Kernel 6.1.27-1-lts
@Luna-Klatzer Luna-Klatzer added the bug Bug or issue in the language or API label Jun 7, 2023
@Luna-Klatzer Luna-Klatzer self-assigned this Jun 7, 2023
Luna-Klatzer added a commit that referenced this issue Jun 7, 2023
The bug was caused by the variable declaration still performing type checking after the semantic error (as expected), but not ensuring the scope declaration is present.
This was referenced Jun 16, 2023
@Luna-Klatzer
Copy link
Member Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug or issue in the language or API
Projects
1 participant