diff --git a/changelogs/changelog_2_0_0.md b/changelogs/changelog_2_0_0.md index 4a15855f4ca27..690258bdc5669 100644 --- a/changelogs/changelog_2_0_0.md +++ b/changelogs/changelog_2_0_0.md @@ -44,6 +44,9 @@ - Enabling `-d:nimPreviewCstringConversion`, `ptr char`, `ptr array[N, char]` and `ptr UncheckedArray[N, char]` don't support conversion to cstring anymore. +- Enabling `-d:nimPreviewProcConversion`, `proc` does not support conversion to + `pointer`. `cast` may be used instead. + - The `gc:v2` option is removed. - The `mainmodule` and `m` options are removed. diff --git a/compiler/nim.cfg b/compiler/nim.cfg index 5e70c2975e2d1..5b418cfd3b2d8 100644 --- a/compiler/nim.cfg +++ b/compiler/nim.cfg @@ -7,6 +7,7 @@ define:nimcore define:nimPreviewFloatRoundtrip define:nimPreviewSlimSystem define:nimPreviewCstringConversion +define:nimPreviewProcConversion define:nimPreviewRangeDefault threads:off diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index 84b99bede61c3..11abc615ccade 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -1380,7 +1380,10 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, result = isEqual of tyNil: result = f.allowsNil of tyProc: - if a.callConv != ccClosure: result = isConvertible + if isDefined(c.c.config, "nimPreviewProcConversion"): + result = isNone + else: + if a.callConv != ccClosure: result = isConvertible of tyPtr: # 'pointer' is NOT compatible to regionized pointers # so 'dealloc(regionPtr)' fails: diff --git a/lib/pure/hashes.nim b/lib/pure/hashes.nim index 8e5770a71f408..daa7f936612fd 100644 --- a/lib/pure/hashes.nim +++ b/lib/pure/hashes.nim @@ -534,7 +534,7 @@ proc hash*[T: tuple | object | proc | iterator {.closure.}](x: T): Hash = when T is "closure": result = hash((rawProc(x), rawEnv(x))) elif T is (proc): - result = hash(pointer(x)) + result = hash(cast[pointer](x)) else: result = 0 for f in fields(x): diff --git a/lib/wrappers/openssl.nim b/lib/wrappers/openssl.nim index fcf52a8d95204..fa72c6c2463e2 100644 --- a/lib/wrappers/openssl.nim +++ b/lib/wrappers/openssl.nim @@ -589,7 +589,7 @@ when not useWinVersion and not defined(macosx) and not defined(android) and useN if p != nil: deallocShared(p) proc CRYPTO_malloc_init*() = - CRYPTO_set_mem_functions(allocWrapper, reallocWrapper, deallocWrapper) + CRYPTO_set_mem_functions(cast[pointer](allocWrapper), cast[pointer](reallocWrapper), cast[pointer](deallocWrapper)) else: proc CRYPTO_malloc_init*() = discard diff --git a/tests/dll/nimhcr_unit.nim b/tests/dll/nimhcr_unit.nim index 0b924bdf75b06..249f3f9f177ad 100644 --- a/tests/dll/nimhcr_unit.nim +++ b/tests/dll/nimhcr_unit.nim @@ -106,14 +106,14 @@ macro carryOutTests(callingConv: untyped): untyped = echo `procName`, " implementation #1 ", x return x + 1 - let fp1 = cast[F](hcrRegisterProc("dummy_module", `procName`, `p1`)) + let fp1 = cast[F](hcrRegisterProc("dummy_module", `procName`, cast[pointer](`p1`))) echo fp1(10) proc `p2`(x: int): int {.placeholder.} = echo `procName`, " implementation #2 ", x return x + 2 - let fp2 = cast[F](hcrRegisterProc("dummy_module", `procName`, `p2`)) + let fp2 = cast[F](hcrRegisterProc("dummy_module", `procName`, cast[pointer](`p2`))) echo fp1(20) echo fp2(20) @@ -121,7 +121,7 @@ macro carryOutTests(callingConv: untyped): untyped = echo `procName`, " implementation #3 ", x return x + 3 - let fp3 = cast[F](hcrRegisterProc("dummy_module", `procName`, `p3`)) + let fp3 = cast[F](hcrRegisterProc("dummy_module", `procName`, cast[pointer](`p3`))) echo fp1(30) echo fp2(30) echo fp3(30) diff --git a/tests/stdlib/config.nims b/tests/stdlib/config.nims index cf97152bab752..dffae2812076d 100644 --- a/tests/stdlib/config.nims +++ b/tests/stdlib/config.nims @@ -1,4 +1,5 @@ switch("styleCheck", "usages") switch("styleCheck", "error") switch("define", "nimPreviewSlimSystem") -switch("define", "nimPreviewCstringConversion") \ No newline at end of file +switch("define", "nimPreviewCstringConversion") +switch("define", "nimPreviewProcConversion") diff --git a/tests/tools/config.nims b/tests/tools/config.nims index b4bb92b300707..0f0cba8b45300 100644 --- a/tests/tools/config.nims +++ b/tests/tools/config.nims @@ -1,2 +1,3 @@ --d:nimPreviewSlimSystem ---d:nimPreviewCstringConversion \ No newline at end of file +--d:nimPreviewCstringConversion +--d:nimPreviewProcConversion diff --git a/tests/types/tissues_types.nim b/tests/types/tissues_types.nim index 7ed0547bfc7e7..275941caec48c 100644 --- a/tests/types/tissues_types.nim +++ b/tests/types/tissues_types.nim @@ -44,11 +44,10 @@ block t5648: g.bar = 3 var - mainPtr1: pointer = main - mainPtr2 = pointer(main) - mainPtr3 = cast[pointer](main) + mainPtr = cast[pointer](main) + mainFromPtr = cast[typeof(main)](mainPtr) - doAssert mainPtr1 == mainPtr2 and mainPtr2 == mainPtr3 + doAssert main == mainFromPtr main()