Coder Social home page Coder Social logo

constructor's People

Contributors

beef331 avatar graveflo avatar knorrfg avatar patitotective avatar philippmdoerner avatar shadowninja55 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

constructor's Issues

example code fails when flag --experimental:strictFuncs is set

when trying the example code:

import constructor/defaults
type Thingy{.defaults.} = object
  a: float = 10 # Can do it this way
  b = "Hmm" # Can also do it this way
  c = 10
implDefaults(Thingy) # Required to embed the procedure
assert initThingy() == Thingy(a: 10, b: "Hmm", c: 10)

with the flag --experimental:strictFuncs set, the compiler complains:
..../.nimble/pkgs/micros-0.1.5/micros/definitions/routines.nim(109, 49) template/generic instantiation of & from here
..../nim-1.6.6/lib/system.nim(1675, 8) Error: '&' can have side effects an object reachable from 'x' is potentially mutated
..../nim-1.6.6/lib/system.nim(1689, 23) the mutation is here
..../nim-1.6.6/lib/system.nim(1689, 23) is the statement that connected the mutation to the parameter

It would be nice to be able to use the lib independently of that flag.

Not working with default values

Taken from a larger project, source is here: https://github.com/ajusa/dalo/blob/master/src/dalo.nim

Here's the code:

proc initField*(label = "", default = "", widget = defaultInput): Field
  Field(label: label, widget: widget, default: default)

The constructor version of this causes a segfault, whereas having the proc above doesn't call a segfault. widget is of type

  Widget* = proc(f: Field, value: string, error: string): VNode {.closure.}

Since it seems to segfault when I call render (which calls the Widget proc) I can only assume that something related to that is causing the segfault. Hopefully that's enough for you, let me know if you need more information!

Unable to construct object with nested fields

type FileInfo* = object
  path*: string
  size*: BiggestInt
  exists*: bool

type Image* = object
  file*: FileInfo
  dest*: string
  date*: DateTime

Doing

proc initImage*(file: FileInfo, dest: string, lastModified: Time): Image =
Image.init(file, dest, lastModified.inZone(local()))

results in the error Error: unhandled exception: index out of bounds, the container is empty [IndexDefect] I can only assume this has to do with the nested object, as your tests seem to pass.

`defaults` does not work on generic types

Attempting to use defaults with generic objects results in compiler errors both with {} and {defTypeConstr}. We likely need to lift the generic parameters and add them to the procedures. Then use Inner[T] everywhere instead of Inner.

@Patitotective no clue if you have any interest in throwing darts and seeing what lands. Totally up to you.

Defaults pragma/implDefaults incorrectly creates `new<MYTYPE>()` proc for object-type

Heyho, I am using constructor together with orm for convenience purposes and stumbled over this bug:

import norm/[model, pragmas]
import constructor/defaults
import std/times

type 
Item* {.defaults, tableName: "atable".} = ref object of Model
  name*: string = ""
  campaign_id*: int64 = -2
  update_datetime*: DateTime = now()
  creation_datetime*: DateTime = now()
  
implDefaults(Item)

let i1 = newItem() # Works but should it?
#let i2 = initItem() # does not compile

According to what we discussed on discord, the object as a value-allocated type Item should create a initItem() in accordance with nim best practices.
Instead it gets a newItem() proc like a heap allocated object.

This appears to be an issue due to inheritance in the type.

For #6 : Add runnable examples and doc comments to macros

We had discussed this one on discord a couple days back. Having runable examples for the macros and doc comments could be useful.

I'll make a PR to add some that you can do with as you please, just wanted to contribute something mildly useful.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.