forked from kcl-lang/kcl
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
259 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,26 @@ | ||
### InvalidSyntaxError (E1001) | ||
|
||
This error indicates that the compiler syntax error has occurred. | ||
KCL will report InvalidSyntaxError when KCL has a syntax error. | ||
|
||
Erroneous code example: | ||
The error code of InvalidSyntaxError is E1001. | ||
|
||
```kcl,E1001 | ||
x = f( | ||
7 ^ -> Expected one of ['all', 'any', 'bin_number', 'dec_number', '**', 'False', 'filter', 'float_number','hex_number', 'lambda', '{', '[', '(', 'long_string', 'not', 'map', '-', '*', 'name', 'None', '~', 'oct_number', '+',')', 'string', 'True', 'Undefined'] | ||
For example: | ||
|
||
``` | ||
a, b = 1, 2 # Multiple assign is illegal in KCL syntax | ||
``` | ||
|
||
The KCL program will cause the following error message. | ||
|
||
```kcl,e1001 | ||
error[E1001]: InvalidSyntax | ||
--> /syntax_error/general/multiple_assign/case0/main.k:1:2 | ||
| | ||
1 | a, b = 1, 2 # Multiple assign is illegal in KCL syntax | ||
| ^ expected statement | ||
| | ||
``` | ||
|
||
Possible resolution: | ||
|
||
Check and fix KCL syntax errors based on the KCL Language Standard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
### KCLTabError (E1002) | ||
|
||
KCL will report `KCLTabError` when KCL has a tab and white space syntax error. | ||
|
||
In KCL, it is forbidden to mix tabs and four spaces in one indentation block. And we recommend only using white spaces or tabs for indentation in the entire KCL project, don’t mix them. | ||
|
||
For example: | ||
|
||
```python | ||
schema Person: | ||
name: str # begin with a tab | ||
age: int # begin with four white spaces, | ||
# and four white spaces != tab in the env | ||
``` | ||
|
||
The KCL program will cause the following error message. | ||
|
||
```shell | ||
error[E1001]: InvalidSyntax | ||
--> File /syntax_error/tab/tab_error_0/main.k:6:5 | ||
| | ||
3 | age: int = 1 | ||
| ^ inconsistent use of tabs and spaces in indentation | ||
| | ||
``` | ||
|
||
Possible resolution: | ||
|
||
- Only use a tab or four white spaces in KCL, do not mix them. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
### IndentationError (E1003) | ||
|
||
KCL will report `KCLIndentationError` when KCL has an indentation syntax error. | ||
|
||
The KCL syntax includes indentation. A tab or four white spaces in KCL represents an indentation. The other cases will be regarded as syntax errors by KCL. | ||
|
||
For example: | ||
|
||
```python | ||
schema Person: | ||
name: str # a tab or four white spaces is legal. | ||
age: int # three white spaces are illegal | ||
info: str # two white spaces is illegal | ||
``` | ||
|
||
The KCL program will cause the following error message. | ||
|
||
```shell | ||
error[E1001]: InvalidSyntax | ||
--> /syntax_error/indent/indent_error_0/main.k:3:4 | ||
| | ||
3 | age: int # three white spaces are illegal | ||
| ^ unindent 3 does not match any outer indentation level | ||
| | ||
``` | ||
|
||
Possible resolution: | ||
|
||
- Only use a tab or four white spaces in the KCL program for indentation. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
### IllegalArgumentSyntaxError (E1I37) | ||
|
||
KCL will report `IllegalArgumentSyntaxError` when KCL has an illegal argument in KCL syntax. | ||
|
||
For example: | ||
|
||
```python | ||
# Parameters without default values | ||
# must be in front of parameters with default values. | ||
a = option(type="list", default={"key": "value"}, "key1") | ||
``` | ||
|
||
The KCL program will cause the following error message. | ||
|
||
```shell | ||
error[E1001]: InvalidSyntax | ||
--> /option/type_convert_fail_2/main.k:3:57 | ||
| | ||
3 | a = option(type="list", default={"key": "value"}, "key1") | ||
| ^ positional argument follows keyword argument | ||
| | ||
``` | ||
|
||
Possible resolution: | ||
|
||
```python | ||
func(input_1, ..., input_n, param_with_key_1 = input_with_key_1, ..., param_with_key_n = input_with_key_n) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,30 @@ | ||
### IllegalInheritError (E2D34) | ||
|
||
This error indicates that invalid inheritance structure has occurred. | ||
KCL will report `IllegalInheritError` when an illegal inheritance occurs in the schema. | ||
|
||
Erroneous code example: | ||
The `ewcode` of `IllegalInheritError` is `E2D34`. | ||
|
||
```kcl | ||
For example: | ||
|
||
```python | ||
schema FullnameMixin: | ||
fullName = "{} {}".format(firstName, lastName) | ||
|
||
schema Scholar(FullnameMixin): | ||
schema Scholar(FullnameMixin): # mixin inheritance is illegal | ||
school: str | ||
``` | ||
|
||
```kcl,E2D34 | ||
KCL Complier Error[E2D34] : Illegal inheritance | ||
---> File /schema/inherit/inherit_mixin_fail/main.k:8:1 | ||
8 |schema Scholar(FullnameMixin): | ||
1 ^ -> Failure | ||
mixin inheritance FullnameMixin is prohibited | ||
The KCL program will cause the following error message. | ||
|
||
```shell | ||
error[E2D34]: IllegalInheritError | ||
--> /schema/inherit/inherit_mixin_fail/main.k:4:16 | ||
| | ||
4 | schema Scholar(FullnameMixin): | ||
| ^ invalid schema inherit object type, expect schema, got 'FullnameMixin' | ||
| | ||
``` | ||
|
||
Possible resolution: | ||
|
||
- Schema supports single inheritance of schema in KCL. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,24 @@ | ||
## CannotFindModule (E2F04) | ||
|
||
This error indicates that the import module is not found. | ||
KCL will report `CannotFindModule` when KCL imports a module that does not exist. | ||
|
||
Erroneous code example: | ||
The `ewcode` of `CannotFindModule` is `E2F04`. | ||
|
||
```kcl,E2F04 | ||
1 |import not_existed_pkg | ||
1 ^^^^^^^^^^^^^^^^^^^^^^ -> Failure | ||
Cannot find the module not_existed_pkg from ./not_existed_pkg | ||
For example: | ||
|
||
```python | ||
import .some0.pkg1 as some00 # some0 not found in package | ||
|
||
Name1 = some00.Name # some0.pkg1.name | ||
``` | ||
|
||
The KCL program will cause the following error message. | ||
|
||
```shell | ||
error[E2F04]: CannotFindModule | ||
--> import_abs_fail_0/app-main/main.k:1:1 | ||
| | ||
1 | import .some0.pkg1 as some00 # some0 not found in package | ||
| Cannot find the module .some0.pkg1 | ||
| | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,35 @@ | ||
### TypeError (E2G22) | ||
|
||
This error indicates that the compiler type error has occurred. | ||
KCL will report `TypeError` when a type error occurs in compiling type check. | ||
|
||
Erroneous code example: | ||
The `ewcode` of `TypeError` is `E2G22`. | ||
|
||
```kcl,E2G22 | ||
1 |a: int = "1" | ||
1 ^ -> got str(1) | ||
expected int, got str(1) | ||
For example: | ||
|
||
```python | ||
schema Person: | ||
firstName: str | ||
lastName: int | ||
|
||
JohnDoe = Person { | ||
"firstName": "John", | ||
"lastName": "Doe" # Type Error,lastName: int,“Doe” is a string. | ||
} | ||
``` | ||
|
||
The KCL program will cause the following error message. | ||
|
||
```shell | ||
error[E2G22]: TypeError | ||
--> type/type_fail_0/main.k:7:5 | ||
| | ||
7 | "lastName": "Doe" # Type Error,lastName: int,“Doe” is a string. | ||
| ^ expected int, got str(Doe) | ||
| | ||
|
||
--> type/type_fail_0/main.k:3:5 | ||
| | ||
3 | lastName: int | ||
| ^ variable is defined here, its type is int, but got str(Doe) | ||
| | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
### UnKnownDecoratorError (E2H13) | ||
|
||
KCL will report `UnKnownDecoratorError` when an unknown decorator is used in KCL. | ||
|
||
The `ewcode` of `UnKnownDecoratorError` is `E2H13`. | ||
|
||
For example: | ||
|
||
```python | ||
@err_deprecated # It is an unknown decorator | ||
schema Person: | ||
firstName: str = "John" | ||
lastName: str | ||
name: str | ||
|
||
JohnDoe = Person { | ||
name: "deprecated" | ||
} | ||
``` | ||
|
||
The KCL program will cause the following error message. | ||
|
||
```shell | ||
error[E2L23]: CompileError | ||
--> deprecated/unknown_fail_1/main.k:1:2 | ||
| | ||
1 | @err_deprecated # This is a error decorator | ||
| ^ UnKnown decorator err_deprecated | ||
| | ||
``` | ||
|
||
Possible resolution: | ||
|
||
- Check whether the decorator exists. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,40 @@ | ||
### UniqueKeyError (E2L28) | ||
|
||
This error indicates that variables with the same name or duplicate definitions. | ||
KCL will report `UniqueKeyError` when duplicate names appear in the KCL code. | ||
|
||
Erroneous code example: | ||
The `ewcode` of `UniqueKeyError` is `E2L28`. | ||
|
||
```kcl | ||
For example: | ||
|
||
```python | ||
schema Person: | ||
name: str = "kcl" | ||
age: int = 1 | ||
|
||
schema Person: | ||
aa: int | ||
|
||
x0 = Person{} | ||
x1 = Person{age:101} | ||
``` | ||
|
||
```kcl,E2L28 | ||
KCL Complier Error[E2L28] : Unique key error | ||
---> File /schema/same_name/main.k:5:1 | ||
5 |schema Person: | ||
1 ^ -> Failure | ||
Variable name 'Person' must be unique in package context | ||
The KCL program will cause the following error message. | ||
|
||
```shell | ||
error[E2L28]: UniqueKeyError | ||
--> /schema/same_name/main.k:5:8 | ||
| | ||
5 | schema Person: | ||
| ^ Unique key error name 'Person' | ||
| | ||
|
||
--> /schema/same_name/main.k:1:8 | ||
| | ||
1 | schema Person: | ||
| ^ The variable 'Person' is declared here | ||
| | ||
``` | ||
|
||
Possible resolution: | ||
|
||
- Check if the name with error has been used. |