mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 08:54:53 +00:00
Automatic dereferencing is removed (#20531)
This commit is contained in:
@@ -46,6 +46,8 @@
|
||||
- Optional parameters in combination with `: body` syntax (RFC #405) are now opt-in via
|
||||
`experimental:flexibleOptionalParams`.
|
||||
|
||||
- Automatic dereferencing (experimental feature) is removed.
|
||||
|
||||
- The `Math.trunc` polyfill for targeting Internet Explorer was
|
||||
previously included in most JavaScript output files.
|
||||
Now, it is only included with `-d:nimJsMathTruncPolyfill`.
|
||||
|
||||
@@ -195,7 +195,7 @@ type
|
||||
ideRecompile, ideChanged, ideType, ideDeclaration
|
||||
|
||||
Feature* = enum ## experimental features; DO NOT RENAME THESE!
|
||||
implicitDeref,
|
||||
implicitDeref, # deadcode; remains here for backwards compatibility
|
||||
dotOperators,
|
||||
callOperator,
|
||||
parallel,
|
||||
|
||||
@@ -580,27 +580,6 @@ proc semOverloadedCall(c: PContext, n, nOrig: PNode,
|
||||
"Non-matching candidates for " & renderTree(n) & "\n" &
|
||||
candidates)
|
||||
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:
|
||||
if efExplain notin flags:
|
||||
# repeat the overload resolution,
|
||||
|
||||
@@ -932,12 +932,6 @@ proc resolveIndirectCall(c: PContext; n, nOrig: PNode;
|
||||
t: PType): TCandidate =
|
||||
initCandidate(c, result, t)
|
||||
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 =
|
||||
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!
|
||||
```
|
||||
|
||||
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:
|
||||
|
||||
```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
|
||||
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
|
||||
=================
|
||||
|
||||
|
||||
@@ -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
|
||||
x3: seq[int]
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user