Commit Graph

832 Commits

Author SHA1 Message Date
konsumlamm
528b6d1c3f Warn when casting to a larger type (#20103)
* Warn when casting to a larger type

* Revert change to error message to fix CI
2022-07-28 15:09:58 +02:00
quantimnot
800cb006e7 Change styleCheck to ignore foreign packages (#19822)
* Change `styleCheck` to ignore foreign packages

* Symbols from foreign packages are now ignored.
* Fixed `styleCheck` violations in `compiler` package.
* Added symbol ownership to custom annotation pragmas.
* Minor refactors to cleanup style check callsites.
* Minor internal documentation of reasons why a symbol isn't checked.

Style violations were fixed in the compiler after thet were exposed by
the changes. The compiler wouldn't compile otherwise.

Symbol ownership for custom pragma annotations is needed for checking
the annotation's style. A NPE was raised otherwise.

Fixes #10201
See also nim-lang/RFCs#456

* Fix a misunderstanding about excluding field style checks

I had refactored the callsites of `styleCheckUse` to apply the DRY
principle, but I misunderstood the field access handling in a template
as a general case. This corrects it.

* Fix some `styleCheck` violations in `compiler/evalffi`

The violations were exposed in CI when the compiler was built with
libffi.

* Removed some uneeded transitionary code

* Add changelog entry

Co-authored-by: quantimnot <quantimnot@users.noreply.github.com>
2022-07-14 14:20:40 +02:00
metagn
5c510a9ab9 allow dots in defined() (#20010)
* allow dots in defined()

refs https://github.com/nim-lang/RFCs/issues/181

* mention accents in older versions
2022-07-12 18:03:58 +02:00
Tanguy
ce4078acd4 Allow recursive closure iterators (#19939) 2022-06-30 23:19:04 +02:00
nc-x
4680ab61c0 Fix fixAbstractType for user defined typeclasses, fixes #19730 & #18409 (#19732) 2022-04-30 15:58:58 +02:00
Ivan Yonchovski
e4a2c2d474 Make sure that field usage preserves the original line info (#19751)
Currently `struct.field` will generate a node with `info` that points to the
symbol definition instead of having the actual node location.
2022-04-29 11:16:07 +02:00
flywind
00775f6880 fix stylecheck bug with nre (#19356)
* stylecheck usages part two: stdlib cleanup

typeinfo.nim: importCompilerProc => importcompilerproc

nre.nim: newLineFlags => newlineFlags

system.nim: JSRoot => JsRoot

ref #19319

* prefer importCompilerProc

* fix stylecheck error with asyncdispatch

it is a partial regression since #12842

* add tests

* don't use echo in tests

* fix stylecheck bug with nre

* Update compiler/linter.nim

* no need to check dotexpr again

* neither did let/var/const
2022-04-08 08:04:46 +02:00
Andreas Rumpf
51df9ff1c7 fixes #19603; some pragmas were really only supported as top level statements. Now this is enforced properly. (#19646) 2022-03-26 06:47:04 +01:00
flywind
d6d36093b1 apply changes from #18017 and some fixes (#19571)
* implements https://github.com/nim-lang/RFCs/issues/369

* deprecate unsafeAddr; extend addr

addr is now available for all addressable locations, unsafeAddr is deprecated and become an alias for addr

* follow @Vindaar's advice

* change the signature of addr

* unsafeAddr => addr (stdlib)

* Update changelog.md

* unsafeAddr => addr (tests)

* Revert "unsafeAddr => addr (stdlib)"

This reverts commit ab83c99c50.

* doc changes; thanks to @konsumlamm

Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com>

* merge

* remove

* fix bug

Co-authored-by: Araq <rumpf_a@web.de>
Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com>
2022-03-01 07:46:08 +01:00
Jason Beetham
fa96e56ad0 Fixed object field access of static objects in generics (#19283) [backport] 2021-12-23 07:12:56 +01:00
hlaaftana
f91867aa31 accept object type node from macros (#19179) 2021-11-24 16:34:42 +01:00
林亦恩
e645be4d0c add ghci like type annotation buildEchoStmt (1049) (#18875)
* add ghci like type annotation buildEchoStmt (1049)

* Update compiler/semexprs.nim

* Update compiler/semexprs.nim

Co-authored-by: flywind <xzsflywind@gmail.com>

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
Co-authored-by: flywind <xzsflywind@gmail.com>
2021-10-13 11:35:47 +02:00
flywind
677969f6ea alternative to #18918 (#18927)
* fix #16558

* add testcase
2021-09-30 16:57:06 +02:00
Andreas Rumpf
6163bdd279 closes #16132 [backport] (#18880)
* closes #16132 [backport]

* fixes #16132 [backport]
2021-09-22 15:07:36 +02:00
Andreas Rumpf
0ad601d3c1 fixes #18856 [backport] (#18879) 2021-09-22 09:43:06 +02:00
Jason Beetham
f8e185fec0 Fixed borrowing dot from aliases (#18854) 2021-09-16 08:48:58 +02:00
Jason Beetham
172253cb55 Dotborrow now works with generic distincts (#18848) 2021-09-14 19:34:52 +02:00
Jason Beetham
5d1608c976 Generic pointer procs now error if no types supplied (#18832)
* more precise logic for pointer procs

* added test for generic pointer procs

* Fixed generic getting bracket expr if erroring
2021-09-11 22:20:22 +02:00
Jason Beetham
30d28bcefc Fixes implicit and explicit generics in procedures (#18808)
* Fixes implicit and explicit generics

* moved block logic into 'maybeInstantiateGeneric'

* Added more tests

* Update compiler/semexprs.nim

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
2021-09-06 20:11:21 +02:00
Jason Beetham
90bfd34250 '[]' can now be used for iterators (#18814) 2021-09-06 15:30:49 +02:00
Andreas Rumpf
cddf8ec6f6 implements https://github.com/nim-lang/RFCs/issues/407 (#18793) 2021-09-03 21:52:24 +02:00
Andreas Rumpf
a273ea70e8 implements overloadable enum values; WIP (#18470)
* implements overloadable enum values
* simpler code
2021-07-28 12:46:28 +02:00
Andreas Rumpf
f4ff276a90 refactoring: removed dead code (#18567) 2021-07-24 00:30:02 +02:00
Andreas Rumpf
70fb377e88 undo RFC #294, it breaks code for no good reason, the compiler can wa… (#18546)
* undo RFC #294, it breaks code for no good reason, the compiler can warn about the construct instead

* Update changelog.md

Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com>

* enable test case

Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com>
2021-07-21 08:51:03 +02:00
Timothee Cour
836b061ae3 improve --declaredLocs to help disambiguate types (generics, aliases etc) (#18389)
* improve --declaredlocs to help disambiguate types (generics, aliases etc)

* avoid a cyclic deps

* fix test after rebase
2021-07-08 12:28:06 +02:00
Andreas Rumpf
97fc95012d fixes #16270 (#18388) 2021-06-29 15:34:39 +02:00
Timothee Cour
87cd9b24a3 add more APIs to compiler/debugutils; re-export it (#18243) 2021-06-18 15:52:08 +02:00
Timothee Cour
c83ac16671 Renamed -d:nimCompilerStackraceHints to -d:nimCompilerStacktraceHints. (#18283) 2021-06-17 00:17:46 -07:00
Andreas Rumpf
f65f760dee fixes #15884 (#18230)
* fixes #15884

* micro optimization
2021-06-10 18:19:20 +02:00
Andreas Rumpf
f10eef29b5 fixes #18059 (#18140)
* fixes #18059
2021-06-02 13:13:23 +02:00
Andreas Rumpf
378ee7f888 feature: the compiler can warn when you use the implicit 'result' variable (#17988) [backport:1.2]
* implements #17855
2021-05-10 23:41:51 +02:00
flywind
6e8f0f8cfc add colon (#17834) 2021-04-24 18:33:29 +01:00
Timothee Cour
2abc936d51 typeof(voidStmt) now works (#17807)
* `typeof(voidStmt)` now works
* remove typeOrVoid
* add condsyms, and reference cligen https://github.com/c-blake/cligen/pull/193
* fixup
* changelog [skip ci]
* fixup
2021-04-23 14:36:38 +02:00
flywind
4471141a1d fix #7535(Poor error message for spawn when a procedure (without calling it)) (#17774) 2021-04-21 17:53:31 +02:00
Clyybber
80389b8053 Revert localErrorNode param order changes (#17809)
* Revert localErrorNode param order changes

* Remove unused globalError overload

* heh
2021-04-21 16:03:30 +02:00
Timothee Cour
8de053d870 fix hintMsgOrigin regression + simplify msgs code (#17805) 2021-04-21 07:00:45 +02:00
Clyybber
438afb4db9 Introduce localErrorNode (#17785) 2021-04-19 17:19:21 +02:00
Timothee Cour
7e94420847 cString => cSourceString; tyCString => tyCstring so that error msgs show cstring, not cString (#17744) 2021-04-17 11:14:09 +02:00
Tanguy Cizain
363467fc00 Fix array's high & low return type for empty arrays (#17705)
* fix array.high/low return type

* Add test for empty array low return type

Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com>

Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com>
2021-04-15 15:45:38 +02:00
Andreas Rumpf
67e28c07f9 IC: first steps towards 'nim check --def --ic:on' (#17714)
* IC: first steps towards 'nim check --def --ic:on'
* IC navigator: deduplicate output lines
* IC navigator: progress
* IC navigator: use a different nimcache entry
* IC navigator: special logic for templates/macros
* IC navigator: proper error messages
* IC navigator: prepare for testing code; document only what currently works somewhat
2021-04-14 16:44:37 +02:00
Timothee Cour
ceadf54d76 iterable[T] (#17196)
* fix failing test toSeq in manual which now works
* changelog
* reject proc fn(a: iterable)
* add iterable to spec
* remove MCS/UFCS limitation that now works
2021-04-11 14:25:41 +02:00
Andreas Rumpf
444658fe58 fixes #17656 (#17657) 2021-04-07 07:46:45 +02:00
Timothee Cour
270964c487 implement RFCs/294 ; disallow enum <=> enum conversion (#16351)
* fix https://github.com/nim-lang/RFCs/issues/294 ; disallow enum <=> enum conversion
* fix the runnableExamples that was the instigator of this RFC
* legacy -d:nimLegacyConvEnumEnum
* use -d:nimLegacyConvEnumEnum in important_package nimgame2
* add test for enum cast
* improve changelog
* add changelog: Changes affecting backward compatibility
* cleanup changelog
* fix changelog
2021-04-03 07:15:21 +02:00
Andreas Rumpf
6c1c8f51b3 IC: green tests (#17311)
* IC: renamed to_packed_ast module to ic module

* IC: don't store the --forceBuild flag, makes it easier to test

* IC: enable hello world test

* Codegen: refactorings for IC; changed the name mangling algorithm

* fixed the HCR regressions

* life is too short for HCR

* tconvexhull is now allowed to use deepCopy

* IC exposed a stdlib bug, required a refactoring

* codegen: code cleanups

* IC: even if a module is outdated, its dependencies might come from disk

* IC: progress

* IC: better name mangling, module IDs are not stable

* IC: another refactoring helping with --ic:on --gc:arc

* disable arraymancer on Windows for the time being

* disable arraymancer altogether

* IC: make basic test work with 'nim cpp'

* IC: progress on --ic:on --gc:arc

* wip; name mangling for type info
2021-03-19 16:53:38 +01:00
Saem Ghani
72b89eff82 semLambda removed, semProcAux reworked (#17379)
* simplified proc-like name ident to symbol code

* wip - reworking generic param sem

* wip - closer to removing nkEmpty generic params

* it's hacky but tests pass

* slowly tweaking semProcAux to take on semLambda

* fix pragma superset check proto vs current

* Set the symbol owner earlier

* partial progress reworking proto

found bug where default values between forward and impl lead to overload
resolution issues.

* simplified pragma handling and callConv checks

Co-authored-by: Clyybber <Clyybber@users.noreply.github.com>

* partially working

* cgexprs issue

* It works!

* comment clean-up

* clean-up asserts, comments, and other bits

* add isGenericParams, inline isGeneric queries

* seeing if this is sufficiently consistent
* can use this approach or continue it in a further PR

* commentary about nullary generics and clean-ups

* fixed a mistake in PNode isGenericRoutine

* Some small cleanups

* Small cleanup

* for func lambdas ensure we use lambda pragmas

* add some basic compileTime func tests

* [ci skip] remove comments

Co-authored-by: Clyybber <Clyybber@users.noreply.github.com>
Co-authored-by: Clyybber <darkmine956@gmail.com>
2021-03-17 19:51:50 +01:00
Andreas Rumpf
2f213db7ee fixes #11225; generic sandwich problems; [backport:1.2] (#17255)
* fixes #11225; generic sandwich problems; [backport:1.2]
* progress
* delegating these symbols must be done via 'bind'
2021-03-09 20:19:24 +01:00
quantimnot
b2b23d723a Fix macros.quote custom op symbol interpolation. (#17256)
Provides a workaround/fix for #7589.
https://github.com/nim-lang/Nim/issues/7589

Updated docs and tutorial to reflect change.

Updated runnableExamples to include an example.

Co-authored-by: name <name@example.com>
2021-03-05 14:41:33 +01:00
Saem Ghani
2aba116bbc when statements branches exit early (#17143)
When statement branches exit early outside of nimvm. In nimvm it seems that all
sides of the branches must be evaluated as the code gen happens at a later
stage, this remains intact.
2021-02-22 12:27:23 +01:00
Saem Ghani
260a5dacb7 fixed dot operator recursive loop & macro suggest (#16922)
* basic stability improvements; refs nimsuggest
* fixed dot operator recursive loop & macro suggest
* hacky fix for run away dot operator sem check

Committing this mostly to make the issue more clear. Perhaps get better
feedback.

* semExprWithType seems like a better place to check
* fixed error messages const case expressions
* Clean-up test
* stopped the dot operator madness

No longer get infinite recursion when seming broken code with a dot
operator macro like in jsffi.

Co-authored-by: Araq <rumpf_a@web.de>
2021-02-15 09:51:05 +01:00
flywind
d447c0fe3f use typeof instead type (#16962) 2021-02-08 09:46:07 +01:00