-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bug where the ctor for structs with VTable was not enforced (#520)
- Loading branch information
1 parent
9c9cf28
commit 230e6e7
Showing
10 changed files
with
118 additions
and
27 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,18 +1,38 @@ | ||
type Visitor struct {} | ||
|
||
type SymbolTable struct {} | ||
|
||
type Visitable interface { | ||
f<bool> accept(Visitor*); | ||
} | ||
|
||
type AstNode struct : Visitable {} | ||
|
||
type AstEntryNode struct : Visitable { | ||
AstNode astNode | ||
SymbolTable* extFunctionScope | ||
bool takesArgs | ||
} | ||
|
||
f<int> main() { | ||
int[3] a = [1, 2, 3]; | ||
int* aPtr = a; | ||
printf("%d\n", *aPtr); | ||
unsafe { | ||
aPtr++; | ||
} | ||
printf("%d\n", *aPtr); | ||
AstEntryNode entryNode; | ||
printf("%d", entryNode.takesArgs); | ||
} | ||
|
||
/*import "bootstrap/util/block-allocator"; | ||
import "bootstrap/util/memory"; | ||
|
||
type ASTNode struct { | ||
int value | ||
} | ||
|
||
p ASTNode.dtor() { | ||
printf("Dtor called!"); | ||
} | ||
|
||
f<int> main() { | ||
DefaultMemoryManager defaultMemoryManager; | ||
IMemoryManager* memoryManager = &defaultMemoryManager; | ||
BlockAllocator<int> allocator = BlockAllocator<int>(memoryManager, 10l); | ||
memoryManager.allocate(10l); | ||
//BlockAllocator<ASTNode> allocator = BlockAllocator<ASTNode>(memoryManager, 10l); | ||
}*/ |
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
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
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
8 changes: 8 additions & 0 deletions
8
test/test-files/typechecker/structs/error-missing-no-args-ctor-ref-fields/exception.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,8 @@ | ||
[Error|Compiler]: | ||
Unresolved soft errors: There are unresolved errors. Please fix them and recompile. | ||
|
||
[Error|Semantic] ./source.spice:7:5: | ||
No matching ctor found: Struct 'TypeWithVTable' misses a no-args constructor | ||
|
||
7 TypeWithVTable v; | ||
^^^^^^^^^^^^^^^^ |
8 changes: 8 additions & 0 deletions
8
test/test-files/typechecker/structs/error-missing-no-args-ctor-ref-fields/source.spice
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 TypeWithVTable struct { | ||
int& refField | ||
} | ||
|
||
f<int> main() { | ||
// Types containing reference fields can't have a default constructor, thus this should fail | ||
TypeWithVTable v; | ||
} |
8 changes: 8 additions & 0 deletions
8
test/test-files/typechecker/structs/error-missing-no-args-ctor-vtable/exception.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,8 @@ | ||
[Error|Compiler]: | ||
Unresolved soft errors: There are unresolved errors. Please fix them and recompile. | ||
|
||
[Error|Semantic] ./source.spice:13:5: | ||
No matching ctor found: Struct 'TypeWithVTable' misses a no-args constructor | ||
|
||
13 TypeWithVTable v; | ||
^^^^^^^^^^^^^^^^ |
14 changes: 14 additions & 0 deletions
14
test/test-files/typechecker/structs/error-missing-no-args-ctor-vtable/source.spice
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,14 @@ | ||
type TypeContainingRefField struct { | ||
int& refField | ||
} | ||
|
||
#[core.compiler.alwaysEmitVTable] | ||
type TypeWithVTable struct { | ||
TypeContainingRefField refFieldStruct | ||
} | ||
|
||
f<int> main() { | ||
// Can't call default ctor, because it can't be generated due to the reference field | ||
// But we need to call it to trigger the generation of the vtable. | ||
TypeWithVTable v; | ||
} |