-
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.
feat: Skip checking of redefined functions (#457)
Closes #431. * Make `Globals.defs` mutable * Add `GuppyModule.unregister` function to remove definitions from a module * Redefining of classes doesn't work because of #456
- Loading branch information
Showing
4 changed files
with
99 additions
and
22 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
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,19 +1,83 @@ | ||
import pytest | ||
|
||
from guppylang.decorator import guppy | ||
from guppylang.module import GuppyModule | ||
|
||
import guppylang.prelude.quantum as quantum | ||
|
||
|
||
def test_redefinition(validate): | ||
def test_func_redefinition(validate): | ||
module = GuppyModule("test") | ||
module.load_all(quantum) | ||
|
||
@guppy(module) | ||
def test() -> bool: | ||
return True | ||
return 5 # Type error on purpose | ||
|
||
@guppy(module) | ||
def test() -> bool: # noqa: F811 | ||
return False | ||
|
||
validate(module.compile()) | ||
|
||
|
||
def test_method_redefinition(validate): | ||
module = GuppyModule("test") | ||
|
||
@guppy.struct(module) | ||
class Test: | ||
x: int | ||
|
||
@guppy(module) | ||
def foo(self: "Test") -> int: | ||
return 1.0 # Type error on purpose | ||
|
||
@guppy(module) | ||
def foo(self: "Test") -> int: | ||
return 1 # Type error on purpose | ||
|
||
validate(module.compile()) | ||
|
||
|
||
@pytest.mark.skip("See https://github.com/CQCL/guppylang/issues/456") | ||
def test_struct_redefinition(validate): | ||
module = GuppyModule("test") | ||
|
||
@guppy.struct(module) | ||
class Test: | ||
x: "blah" # Non-existing type | ||
|
||
@guppy.struct(module) | ||
class Test: | ||
y: int | ||
|
||
@guppy(module) | ||
def main(x: int) -> Test: | ||
return Test(x) | ||
|
||
validate(module.compile()) | ||
|
||
|
||
@pytest.mark.skip("See https://github.com/CQCL/guppylang/issues/456") | ||
def test_struct_method_redefinition(validate): | ||
module = GuppyModule("test") | ||
|
||
@guppy.struct(module) | ||
class Test: | ||
x: int | ||
|
||
@guppy(module) | ||
def foo(self: "Test") -> int: | ||
return 1.0 # Type error on purpose | ||
|
||
@guppy.struct(module) | ||
class Test: | ||
y: int | ||
|
||
@guppy(module) | ||
def bar(self: "Test") -> int: | ||
return self.y | ||
|
||
@guppy(module) | ||
def main(x: int) -> int: | ||
return Test(x).bar() | ||
|
||
validate(module.compile()) | ||
|