Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ rounding guarantees (via the
avoid conflicts with `system.default`, so named argument usage for this
parameter like `getOrDefault(..., default = ...)` will have to be changed.

- Typedesc field access on object/tuple types (e.g. `Foo[int].val`) is now
restricted to `typeof` context. Use `--legacy:typedescFieldAccess` to restore
the previous behavior of allowing it outside `typeof`.

- With `-d:nimPreviewCheckedClose`, the `close` function in the `std/syncio` module now raises an IO exception in case of an error.

- Unknown warnings and hints now gives warnings `warnUnknownNotes` instead of
Expand Down
3 changes: 3 additions & 0 deletions compiler/options.nim
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@ type
procParamTypeBackendAliases
## Keep the old proc type compatibility rules that ignore backend
## c type aliases.
typedescFieldAccess
## Allow typedesc field access on object/tuple types outside of
## typeof context.

SymbolFilesOption* = enum
disabledSf, writeOnlySf, readOnlySf, v2Sf, stressTest
Expand Down
3 changes: 2 additions & 1 deletion compiler/semexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1500,7 +1500,8 @@ proc tryReadingTypeField(c: PContext, n: PNode, i: PIdent, ty: PType): PNode =
markUsed(c, n.info, f)
onUse(n.info, f)
of tyObject, tyTuple:
if ty.n != nil and ty.n.kind == nkRecList:
if (c.inTypeofContext > 0 or typedescFieldAccess in c.config.legacyFeatures) and
ty.n != nil and ty.n.kind == nkRecList:
let field = lookupInRecord(ty.n, i)
if field != nil:
n.typ = makeTypeDesc(c, field.typ)
Expand Down
4 changes: 2 additions & 2 deletions lib/pure/nimprof.nim
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ proc writeProfile() {.noconv.} =
var perProc = initCountTable[string]()
for i in 0..entries-1:
var dups = initHashSet[string]()
for ii in 0..high(StackTrace.lines):
for ii in 0..high(typeof(StackTrace.lines)):
let procname = profileData[i].st[ii]
if isNil(procname): break
let p = $procname
Expand All @@ -201,7 +201,7 @@ proc writeProfile() {.noconv.} =
writeLine(f, "Entry: ", i+1, "/", entries, " Calls: ",
profileData[i].total // totalCalls, " [sum: ", sum, "; ",
sum // totalCalls, "]")
for ii in 0..high(StackTrace.lines):
for ii in 0..high(typeof(StackTrace.lines)):
let procname = profileData[i].st[ii]
let filename = profileData[i].st.files[ii]
if isNil(procname): break
Expand Down
2 changes: 1 addition & 1 deletion tests/concepts/tmapconcept.nim
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ static:
ok seq[int] is Enumerable[int]
ok seq[string] is Enumerable
ok seq[int] is Enumerable[SomeNumber]
ok SparseSeq.data is Enumerable
ok typeof(SparseSeq.data) is Enumerable
no seq[string] is Enumerable[int]
no int is Enumerable
no int is Enumerable[int]
Expand Down
2 changes: 1 addition & 1 deletion tests/metatype/ttypedesc3.nim
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ type
Foo[T] = object
val: T

var x: Foo[int].val
var x: typeof(Foo[int].val)
inc(x)
echo x
11 changes: 11 additions & 0 deletions tests/metatype/ttypedesc_field_legacy.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
discard """
matrix: "--legacy:typedescFieldAccess"
output: "4"
"""

type
Foo[T] = object
val: T

var x: Foo[int].val = 4
echo x
2 changes: 1 addition & 1 deletion tests/pragmas/tcustom_pragma.nim
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ TypeDef
Baz {.expectedAst(typeAst).} = object
x: string

static: doAssert Baz.x is string
static: doAssert typeof(Baz.x) is string

const procAst = """
ProcDef
Expand Down
Loading