-
Notifications
You must be signed in to change notification settings - Fork 39
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
Language specification in form of tests #10
Comments
Nice comment on macros. |
For tests that involve types also check everything with distinct.
type
A = distinct int
B[T] = distinct A
C = distinct B[string] |
I would much rather prefer to have some built-in language construct to assert compilation errors, instead of testament hack let failure = getFailedNkErrorNodes:
SomeCodeThatMakesNoSenseSemantically
doAssert failure.description.contains "illegal recursion in type 'Object'" discard """
cmd: "nim check $file"
nimout: '''teffects1.nim(22, 28) template/generic instantiation from here
teffects1.nim(23, 13) Error: can raise an unlisted exception: ref IOError
teffects1.nim(22, 29) Hint: 'lier' cannot raise 'IO2Error' [XCannotRaiseY]
teffects1.nim(38, 21) Error: type mismatch: got <proc (x: int): string{.noSideEffect, gcsafe, locks: 0.}> but expected 'MyProcType = proc (x: int): string{.closure.}'
.raise effects differ'''
"""
{.push warningAsError[Effect]: on.}
type
TObj {.pure, inheritable.} = object
TObjB = object of TObj
a, b, c: string
IO2Error = ref object of IOError
proc forw: int {. .}
proc lier(): int {.raises: [IO2Error].} =
#[tt.Hint ^ 'lier' cannot raise 'IO2Error' [XCannotRaiseY] ]#
writeLine stdout, "arg" #[tt.Error
^ can raise an unlisted exception: ref IOError
]#
proc forw: int =
raise newException(IOError, "arg")
{.push raises: [Defect].}
type
MyProcType* = proc(x: int): string #{.raises: [ValueError, Defect].}
proc foo(x: int): string {.raises: [ValueError].} =
if x > 9:
raise newException(ValueError, "Use single digit")
$x
var p: MyProcType = foo #[tt.Error
^
type mismatch: got <proc (x: int): string{.noSideEffect, gcsafe, locks: 0.}> but expected 'MyProcType = proc (x: int): string{.closure.}'
]#
{.pop.}
{.pop.}
|
Todo items from specification PR reviews by @saem
|
There is another thing important about generics. Generic instanciation time needs to be specified. Generally speaking generics are instanciated at first usage. And this alone wouldn't need a specificaiton, But nim doesn't order independent. The order in which functions are declared matters. And the amount of converters and functions and types known to the compiler at the time a generic is instanciated affects what the generic will eventually resolve to. It might be that the generic instanciates with a converter function too early. At a later instanciation time the generic might have found a better overload without conversion. |
Maybe just a |
min/max value ranges for enums type
c_git_diff_option_t* = enum
c_GIT_DIFF_NORMAL = 0 shl 0
c_GIT_DIFF_IGNORE_BLANK_LINES = 1 shl 31
^ ok for |
int is 32 bit for JS VM/backend; this works type
c_git_diff_option_t* = enum
c_GIT_DIFF_NORMAL = 0 shl 0
c_GIT_DIFF_IGNORE_BLANK_LINES = 1'i64 shl 31 |
Thanks, @xflywind |
I'm poking at pragmas as part of nkError work, please add as tests. For reference the nkRrror/pragma work is here: d2368ef#diff-1d1109c3f7bc16cf4e770fe792e9073bff67591721f3c72b96cb4b4a3b76bd88R806 |
I think it would be a good idea to also specify how compiler reads the environment - |
https://github.com/nim-lang/Nim/labels/accepts%20invalid as a start |
Specify and provide examples of where each defect is raised, and if possible - how it can be prevented (like cast to unchecked assign, maybe there are some extra features like these that I don't know of). |
Language specification should include specific explanation of some basic concepts that are considered as "no need to explain, obvious to everyone". If anything, this could be used as a basis for introducing newcomers to a fundamentally new concepts that might not exist in their language.
|
Fundamental concepts that aren't or are poorly described:
|
From the tests above -
|
Split into smaller todo lists |
Similarly to the https://github.com/nim-works/nimskull/tree/devel/tests/lang - implement language specification in form of proper tests. There are a lot of things to be checked, but a rough list includes at least (suggestions for more bullet points to test are welcome).
Example implementation PRs
The text was updated successfully, but these errors were encountered: