Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

marshal.load() regression? #7854

Closed
simonkrauter opened this issue May 21, 2018 · 2 comments
Closed

marshal.load() regression? #7854

simonkrauter opened this issue May 21, 2018 · 2 comments

Comments

@simonkrauter
Copy link
Contributor

Example program:

import marshal
import streams
type MyType = ref object
  field*: string
var list: seq[MyType]
let stream = newFileStream("input_file.json", fmRead)
marshal.load(stream, list)

Gives compilation error:
Error: for a 'var' type a variable needs to be passed; but 'seq[MyType](list)' is immutable

Nim Compiler Version 0.18.1 [Linux: amd64]
Compiled at 2018-05-20
git hash: dedf0f3
active boot switches: -d:release

Works with Nim 0.18.0.

@sinkingsugar
Copy link
Contributor

I'm having the same issue after pulling devel.

@Vindaar
Copy link
Contributor

Vindaar commented Aug 28, 2018

Since I was curious what the issue is, I tried to remove everything that's not needed from the example in the OP. It seems to come down to a generic var argument at the second argument + an inherited type.
To summarize:

type
  Stream* = ref StreamObj
  StreamObj* = object of RootObj

  InhStream* = ref InhStreamObj
  InhStreamObj* = object of Stream
    f: string

proc newInhStream*(f: string): InhStream =
  new(result)
  result.f = f

var val: int
let str = newInhStream("input_file.json")

block:
  # works:
  proc load[T](data: var T, s: Stream) =
    discard
  load(val, str)

block:
  # works
  proc load[T](s: Stream, data: T) =
    discard
  load(str, val)

block:
  # broken
  proc load[T](s: Stream, data: var T) =
    discard
  load(str, val)

edit: specifying T further in the broken case, makes it also work. I just don't quite understand which type breaks it. I allowed all types I could think and concat them via | and it still works. :S

Araq added a commit that referenced this issue Aug 29, 2018
@Araq Araq closed this as completed in e98e214 Aug 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants