'func' is now an alias for 'proc .noSideEffect'

This commit is contained in:
Andreas Rumpf 2018-04-12 17:04:15 +02:00
commit ea8afebf8c
2 changed files with 10 additions and 7 deletions

View file

@ -35,6 +35,7 @@
- Dot calls combined with explicit generic instantiations can now be written - Dot calls combined with explicit generic instantiations can now be written
as ``x.y[:z]``. ``x.y[:z]`` that is transformed into ``y[z](x)`` in the parser. as ``x.y[:z]``. ``x.y[:z]`` that is transformed into ``y[z](x)`` in the parser.
- ``func`` is now an alias for ``proc {.noSideEffect.}``.
### Language changes ### Language changes
@ -43,7 +44,7 @@
the use of `static[T]` types. the use of `static[T]` types.
(#6415) (#6415)
- Native C++ exceptions can now be imported with `importcpp` pragma. - Native C++ exceptions can now be imported with `importcpp` pragma.
Imported exceptions can be raised and caught just like Nim exceptions. Imported exceptions can be raised and caught just like Nim exceptions.
More details in language manual. More details in language manual.

View file

@ -264,7 +264,7 @@ proc semTry(c: PContext, n: PNode): PNode =
if isImportedException(typ): if isImportedException(typ):
is_imported = true is_imported = true
elif not isException(typ): elif not isException(typ):
localError(typeNode.info, errExprCannotBeRaised) localError(typeNode.info, errExprCannotBeRaised)
if containsOrIncl(check, typ.id): if containsOrIncl(check, typ.id):
localError(typeNode.info, errExceptionAlreadyHandled) localError(typeNode.info, errExceptionAlreadyHandled)
@ -289,7 +289,7 @@ proc semTry(c: PContext, n: PNode): PNode =
if a.len == 2 and a[0].kind == nkBracket: if a.len == 2 and a[0].kind == nkBracket:
# rewrite ``except [a, b, c]: body`` -> ```except a, b, c: body``` # rewrite ``except [a, b, c]: body`` -> ```except a, b, c: body```
a.sons[0..0] = a[0].sons a.sons[0..0] = a[0].sons
if a.len == 2 and a[0].isInfixAs(): if a.len == 2 and a[0].isInfixAs():
# support ``except Exception as ex: body`` # support ``except Exception as ex: body``
let is_imported = semExceptBranchType(a[0][1]) let is_imported = semExceptBranchType(a[0][1])
@ -310,7 +310,7 @@ proc semTry(c: PContext, n: PNode): PNode =
if is_native and is_imported: if is_native and is_imported:
localError(a[0].info, "Mix of imported and native exception types is not allowed in one except branch") localError(a[0].info, "Mix of imported and native exception types is not allowed in one except branch")
elif a.kind != nkFinally: elif a.kind != nkFinally:
illFormedAst(n) illFormedAst(n)
@ -744,12 +744,12 @@ proc semRaise(c: PContext, n: PNode): PNode =
result = n result = n
checkSonsLen(n, 1) checkSonsLen(n, 1)
if n[0].kind != nkEmpty: if n[0].kind != nkEmpty:
n[0] = semExprWithType(c, n[0]) n[0] = semExprWithType(c, n[0])
let typ = n[0].typ let typ = n[0].typ
if not isImportedException(typ): if not isImportedException(typ):
if typ.kind != tyRef or typ.lastSon.kind != tyObject: if typ.kind != tyRef or typ.lastSon.kind != tyObject:
localError(n.info, errExprCannotBeRaised) localError(n.info, errExprCannotBeRaised)
@ -1513,7 +1513,9 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind,
n.sons[patternPos] = semPattern(c, n.sons[patternPos]) n.sons[patternPos] = semPattern(c, n.sons[patternPos])
if s.kind == skIterator: if s.kind == skIterator:
s.typ.flags.incl(tfIterator) s.typ.flags.incl(tfIterator)
elif s.kind == skFunc:
incl(s.flags, sfNoSideEffect)
incl(s.typ.flags, tfNoSideEffect)
var proto = searchForProc(c, oldScope, s) var proto = searchForProc(c, oldScope, s)
if proto == nil or isAnon: if proto == nil or isAnon:
if s.kind == skIterator: if s.kind == skIterator: