Automatic dereferencing is removed (#20531)
This commit is contained in:
parent
b8def03575
commit
d954e698b3
8 changed files with 18 additions and 104 deletions
|
|
@ -46,6 +46,8 @@
|
||||||
- Optional parameters in combination with `: body` syntax (RFC #405) are now opt-in via
|
- Optional parameters in combination with `: body` syntax (RFC #405) are now opt-in via
|
||||||
`experimental:flexibleOptionalParams`.
|
`experimental:flexibleOptionalParams`.
|
||||||
|
|
||||||
|
- Automatic dereferencing (experimental feature) is removed.
|
||||||
|
|
||||||
- The `Math.trunc` polyfill for targeting Internet Explorer was
|
- The `Math.trunc` polyfill for targeting Internet Explorer was
|
||||||
previously included in most JavaScript output files.
|
previously included in most JavaScript output files.
|
||||||
Now, it is only included with `-d:nimJsMathTruncPolyfill`.
|
Now, it is only included with `-d:nimJsMathTruncPolyfill`.
|
||||||
|
|
|
||||||
|
|
@ -195,7 +195,7 @@ type
|
||||||
ideRecompile, ideChanged, ideType, ideDeclaration
|
ideRecompile, ideChanged, ideType, ideDeclaration
|
||||||
|
|
||||||
Feature* = enum ## experimental features; DO NOT RENAME THESE!
|
Feature* = enum ## experimental features; DO NOT RENAME THESE!
|
||||||
implicitDeref,
|
implicitDeref, # deadcode; remains here for backwards compatibility
|
||||||
dotOperators,
|
dotOperators,
|
||||||
callOperator,
|
callOperator,
|
||||||
parallel,
|
parallel,
|
||||||
|
|
|
||||||
|
|
@ -580,27 +580,6 @@ proc semOverloadedCall(c: PContext, n, nOrig: PNode,
|
||||||
"Non-matching candidates for " & renderTree(n) & "\n" &
|
"Non-matching candidates for " & renderTree(n) & "\n" &
|
||||||
candidates)
|
candidates)
|
||||||
result = semResolvedCall(c, r, n, flags)
|
result = semResolvedCall(c, r, n, flags)
|
||||||
elif implicitDeref in c.features and canDeref(n):
|
|
||||||
# try to deref the first argument and then try overloading resolution again:
|
|
||||||
#
|
|
||||||
# XXX: why is this here?
|
|
||||||
# it could be added to the long list of alternatives tried
|
|
||||||
# inside `resolveOverloads` or it could be moved all the way
|
|
||||||
# into sigmatch with hidden conversion produced there
|
|
||||||
#
|
|
||||||
n[1] = n[1].tryDeref
|
|
||||||
var r = resolveOverloads(c, n, nOrig, filter, flags, errors, efExplain in flags)
|
|
||||||
if r.state == csMatch: result = semResolvedCall(c, r, n, flags)
|
|
||||||
else:
|
|
||||||
# get rid of the deref again for a better error message:
|
|
||||||
n[1] = n[1][0]
|
|
||||||
#notFoundError(c, n, errors)
|
|
||||||
if efExplain notin flags:
|
|
||||||
# repeat the overload resolution,
|
|
||||||
# this time enabling all the diagnostic output (this should fail again)
|
|
||||||
discard semOverloadedCall(c, n, nOrig, filter, flags + {efExplain})
|
|
||||||
elif efNoUndeclared notin flags:
|
|
||||||
notFoundError(c, n, errors)
|
|
||||||
else:
|
else:
|
||||||
if efExplain notin flags:
|
if efExplain notin flags:
|
||||||
# repeat the overload resolution,
|
# repeat the overload resolution,
|
||||||
|
|
|
||||||
|
|
@ -932,12 +932,6 @@ proc resolveIndirectCall(c: PContext; n, nOrig: PNode;
|
||||||
t: PType): TCandidate =
|
t: PType): TCandidate =
|
||||||
initCandidate(c, result, t)
|
initCandidate(c, result, t)
|
||||||
matches(c, n, nOrig, result)
|
matches(c, n, nOrig, result)
|
||||||
if result.state != csMatch:
|
|
||||||
# try to deref the first argument:
|
|
||||||
if implicitDeref in c.features and canDeref(n):
|
|
||||||
n[1] = n[1].tryDeref
|
|
||||||
initCandidate(c, result, t)
|
|
||||||
matches(c, n, nOrig, result)
|
|
||||||
|
|
||||||
proc bracketedMacro(n: PNode): PSym =
|
proc bracketedMacro(n: PNode): PSym =
|
||||||
if n.len >= 1 and n[0].kind == nkSym:
|
if n.len >= 1 and n[0].kind == nkSym:
|
||||||
|
|
|
||||||
|
|
@ -1984,10 +1984,6 @@ dereferencing operations for reference types:
|
||||||
# no need to write n[].data; in fact n[].data is highly discouraged!
|
# no need to write n[].data; in fact n[].data is highly discouraged!
|
||||||
```
|
```
|
||||||
|
|
||||||
Automatic dereferencing can be performed for the first argument of a routine
|
|
||||||
call, but this is an experimental feature and is described [here](
|
|
||||||
manual_experimental.html#automatic-dereferencing).
|
|
||||||
|
|
||||||
In order to simplify structural type checking, recursive tuples are not valid:
|
In order to simplify structural type checking, recursive tuples are not valid:
|
||||||
|
|
||||||
```nim
|
```nim
|
||||||
|
|
|
||||||
|
|
@ -286,29 +286,6 @@ scope. Therefore, the following will *fail to compile:*
|
||||||
This feature will likely be replaced with a better solution to remove
|
This feature will likely be replaced with a better solution to remove
|
||||||
the need for forward declarations.
|
the need for forward declarations.
|
||||||
|
|
||||||
|
|
||||||
Automatic dereferencing
|
|
||||||
=======================
|
|
||||||
|
|
||||||
Automatic dereferencing is performed for the first argument of a routine call.
|
|
||||||
This feature has to be enabled via `{.experimental: "implicitDeref".}`:
|
|
||||||
|
|
||||||
```nim
|
|
||||||
{.experimental: "implicitDeref".}
|
|
||||||
|
|
||||||
type
|
|
||||||
NodeObj = object
|
|
||||||
# ...
|
|
||||||
Node = ref NodeObj
|
|
||||||
|
|
||||||
proc depth(x: NodeObj): int = ...
|
|
||||||
|
|
||||||
let n = Node()
|
|
||||||
echo n.depth
|
|
||||||
# no need to write n[].depth
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
Special Operators
|
Special Operators
|
||||||
=================
|
=================
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,49 +0,0 @@
|
||||||
discard """
|
|
||||||
output: '''
|
|
||||||
1
|
|
||||||
2
|
|
||||||
3
|
|
||||||
4
|
|
||||||
2
|
|
||||||
88
|
|
||||||
timplicit done
|
|
||||||
'''
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
for x in [1, 2, 3, 4]:
|
|
||||||
echo x
|
|
||||||
|
|
||||||
|
|
||||||
type
|
|
||||||
TValue* {.pure, final.} = object of RootObj
|
|
||||||
a: int
|
|
||||||
PValue = ref TValue
|
|
||||||
PPValue = ptr PValue
|
|
||||||
|
|
||||||
|
|
||||||
var x: PValue
|
|
||||||
new x
|
|
||||||
var sp: PPValue = addr x
|
|
||||||
|
|
||||||
sp.a = 2
|
|
||||||
if sp.a == 2: echo 2 # with sp[].a the error is gone
|
|
||||||
|
|
||||||
# Test the new auto-deref a little
|
|
||||||
|
|
||||||
{.experimental.}
|
|
||||||
|
|
||||||
proc p(x: var int; y: int) = x += y
|
|
||||||
|
|
||||||
block:
|
|
||||||
var x: ref int
|
|
||||||
new(x)
|
|
||||||
|
|
||||||
x.p(44)
|
|
||||||
|
|
||||||
var indirect = p
|
|
||||||
x.indirect(44)
|
|
||||||
|
|
||||||
echo x[]
|
|
||||||
|
|
||||||
echo "timplicit done"
|
|
||||||
|
|
@ -57,3 +57,18 @@ block: # bug #14698
|
||||||
x1: int
|
x1: int
|
||||||
x3: seq[int]
|
x3: seq[int]
|
||||||
doAssert t[].sizeof == Foo1.sizeof
|
doAssert t[].sizeof == Foo1.sizeof
|
||||||
|
|
||||||
|
# bug #147
|
||||||
|
type
|
||||||
|
TValue* {.pure, final.} = object of RootObj
|
||||||
|
a: int
|
||||||
|
PValue = ref TValue
|
||||||
|
PPValue = ptr PValue
|
||||||
|
|
||||||
|
|
||||||
|
var x: PValue
|
||||||
|
new x
|
||||||
|
var sp: PPValue = addr x
|
||||||
|
|
||||||
|
sp.a = 2
|
||||||
|
doAssert sp.a == 2
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue