-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Typechecker: support decorator declarations (#559)
This involves rudimentary typechecking of fields, and adding the backing struct of the decorator into the scope like any ordinary `type` declaration. Also, in order to get things to typecheck properly, I added decorator declarations for the existing usages of decorators in the compiler: `@noreturn`, `@external`, and `@intrinsic`.
- Loading branch information
Showing
21 changed files
with
725 additions
and
71 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
decorator bar { | ||
a: String | ||
} | ||
|
||
@bar(a: "a") | ||
func foo(): Int { | ||
val a = 1 + [] | ||
val (a, b) = foobar | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
pub decorator FromOtherModule1 { | ||
pub a: Int | ||
pub b: Int | ||
} | ||
|
||
pub decorator FromOtherModule2 { | ||
pub a: Int | ||
} |
8 changes: 8 additions & 0 deletions
8
projects/compiler/test/typechecker/decorators/error_enum_as_decorator.abra
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,8 @@ | ||
enum Foo { | ||
Bar | ||
} | ||
|
||
@Foo.Bar(b: "asdf") | ||
func foo() { | ||
|
||
} |
4 changes: 4 additions & 0 deletions
4
projects/compiler/test/typechecker/decorators/error_enum_as_decorator.out
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,4 @@ | ||
Error at %TEST_DIR%/typechecker/decorators/error_enum_as_decorator.abra:5:5 | ||
Unexpected token '.', expected one of 'val', 'var', 'func', 'type', 'enum', 'decorator', '@', 'pub': | ||
| @Foo.Bar(b: "asdf") | ||
^ |
5 changes: 5 additions & 0 deletions
5
projects/compiler/test/typechecker/decorators/error_noncomptime_field.abra
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,5 @@ | ||
decorator Bar { | ||
p: Person | ||
} | ||
|
||
type Person { name: String } |
6 changes: 6 additions & 0 deletions
6
projects/compiler/test/typechecker/decorators/error_noncomptime_field.out
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,6 @@ | ||
Error at %TEST_DIR%/typechecker/decorators/error_noncomptime_field.abra:2:3 | ||
Forbidden field type for decorator 'Bar' | ||
| p: Person | ||
^ | ||
This field has type 'Person', which is not allowed for fields of decorators. | ||
Decorators' fields must be one of: Int, Float, Bool, String |
6 changes: 6 additions & 0 deletions
6
projects/compiler/test/typechecker/decorators/error_too_few_args.abra
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,6 @@ | ||
decorator Bar { | ||
a: String | ||
} | ||
|
||
@Bar | ||
func foo() {} |
5 changes: 5 additions & 0 deletions
5
projects/compiler/test/typechecker/decorators/error_too_few_args.out
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,5 @@ | ||
Error at %TEST_DIR%/typechecker/decorators/error_too_few_args.abra:5:2 | ||
Invalid instantiation | ||
| @Bar | ||
^ | ||
The following required fields are missing: 'a' |
6 changes: 6 additions & 0 deletions
6
projects/compiler/test/typechecker/decorators/error_too_many_args.abra
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,6 @@ | ||
decorator Bar { | ||
a: String | ||
} | ||
|
||
@Bar("asdf", 123) | ||
func foo() {} |
5 changes: 5 additions & 0 deletions
5
projects/compiler/test/typechecker/decorators/error_too_many_args.out
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,5 @@ | ||
Error at %TEST_DIR%/typechecker/decorators/error_too_many_args.abra:5:14 | ||
Too many arguments for invocation | ||
| @Bar("asdf", 123) | ||
^ | ||
Expected no more than 1 argument, but 2 were passed |
8 changes: 8 additions & 0 deletions
8
projects/compiler/test/typechecker/decorators/error_type_as_decorator.abra
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,8 @@ | ||
type Foo { | ||
a: String | ||
} | ||
|
||
@Foo(b: "asdf") | ||
func foo() { | ||
|
||
} |
4 changes: 4 additions & 0 deletions
4
projects/compiler/test/typechecker/decorators/error_type_as_decorator.out
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,4 @@ | ||
Error at %TEST_DIR%/typechecker/decorators/error_type_as_decorator.abra:5:2 | ||
Cannot use non-decorator type as a decorator | ||
| @Foo(b: "asdf") | ||
^ |
7 changes: 7 additions & 0 deletions
7
projects/compiler/test/typechecker/decorators/error_unlabeled_args.abra
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,7 @@ | ||
decorator Bar { | ||
a: String | ||
b: Int | ||
} | ||
|
||
@Bar("asdf", 123) | ||
func foo() {} |
5 changes: 5 additions & 0 deletions
5
projects/compiler/test/typechecker/decorators/error_unlabeled_args.out
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,5 @@ | ||
Error at %TEST_DIR%/typechecker/decorators/error_unlabeled_args.abra:6:6 | ||
Invalid instantiation | ||
| @Bar("asdf", 123) | ||
^ | ||
Calls of type constructors must include argument labels |
18 changes: 18 additions & 0 deletions
18
projects/compiler/test/typechecker/decorators/function_decorator.abra
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,18 @@ | ||
import FromOtherModule1, FromOtherModule2 from "./_exports" | ||
|
||
decorator Bar { | ||
a: String | ||
} | ||
|
||
// no necessary label if only one argument | ||
@Bar("asdf") | ||
func f1() {} | ||
|
||
@Bar(a: "asdf") | ||
func f2() {} | ||
|
||
@FromOtherModule1(a: 3, b: 1) | ||
func f3() {} | ||
|
||
@FromOtherModule2(4) | ||
func f4() {} |
Oops, something went wrong.