Fix object variants - nim issue 1286

This commit is contained in:
Ganesh Viswanathan 2019-05-31 16:58:54 -05:00
commit d800fb4525
3 changed files with 16 additions and 21 deletions

View file

@ -1015,7 +1015,7 @@ proc test(options: Options) =
let (_, name, ext) = file.path.splitFile() let (_, name, ext) = file.path.splitFile()
if ext == ".nim" and name[0] == 't' and file.kind in {pcFile, pcLinkToFile}: if ext == ".nim" and name[0] == 't' and file.kind in {pcFile, pcLinkToFile}:
var optsCopy = options.briefClone() var optsCopy = options.briefClone()
optsCopy.action.typ = actionCompile optsCopy.action = Action(typ: actionCompile)
optsCopy.action.file = file.path optsCopy.action.file = file.path
optsCopy.action.backend = "c" optsCopy.action.backend = "c"
optsCopy.action.compileOptions = @[] optsCopy.action.compileOptions = @[]

View file

@ -238,7 +238,7 @@ proc getBinDir*(options: Options): string =
options.getNimbleDir() / "bin" options.getNimbleDir() / "bin"
proc parseCommand*(key: string, result: var Options) = proc parseCommand*(key: string, result: var Options) =
result.action.typ = parseActionType(key) result.action = Action(typ: parseActionType(key))
initAction(result, key) initAction(result, key)
proc parseArgument*(key: string, result: var Options) = proc parseArgument*(key: string, result: var Options) =
@ -329,7 +329,7 @@ proc parseFlag*(flag, val: string, result: var Options, kind = cmdLongOption) =
raise newException(NimbleError, "Unknown option: --" & flag) raise newException(NimbleError, "Unknown option: --" & flag)
proc initOptions*(): Options = proc initOptions*(): Options =
result.action.typ = actionNil result.action = Action(typ: actionNil)
result.pkgInfoCache = newTable[string, PackageInfo]() result.pkgInfoCache = newTable[string, PackageInfo]()
result.nimbleDir = "" result.nimbleDir = ""
result.verbosity = HighPriority result.verbosity = HighPriority

View file

@ -130,34 +130,32 @@ proc contains*(ran: VersionRange, ver: Version): bool =
return withinRange(ver, ran) return withinRange(ver, ran)
proc makeRange*(version: string, op: string): VersionRange = proc makeRange*(version: string, op: string): VersionRange =
new(result)
if version == "": if version == "":
raise newException(ParseVersionError, raise newException(ParseVersionError,
"A version needs to accompany the operator.") "A version needs to accompany the operator.")
case op case op
of ">": of ">":
result.kind = verLater result = VersionRange(kind: verLater)
of "<": of "<":
result.kind = verEarlier result = VersionRange(kind: verEarlier)
of ">=": of ">=":
result.kind = verEqLater result = VersionRange(kind: verEqLater)
of "<=": of "<=":
result.kind = verEqEarlier result = VersionRange(kind: verEqEarlier)
of "": of "":
result.kind = verEq result = VersionRange(kind: verEq)
else: else:
raise newException(ParseVersionError, "Invalid operator: " & op) raise newException(ParseVersionError, "Invalid operator: " & op)
result.ver = Version(version) result.ver = Version(version)
proc parseVersionRange*(s: string): VersionRange = proc parseVersionRange*(s: string): VersionRange =
# >= 1.5 & <= 1.8 # >= 1.5 & <= 1.8
new(result)
if s.len == 0: if s.len == 0:
result.kind = verAny result = VersionRange(kind: verAny)
return return
if s[0] == '#': if s[0] == '#':
result.kind = verSpecial result = VersionRange(kind: verSpecial)
result.spe = s.Version result.spe = s.Version
return return
@ -169,7 +167,7 @@ proc parseVersionRange*(s: string): VersionRange =
of '>', '<', '=': of '>', '<', '=':
op.add(s[i]) op.add(s[i])
of '&': of '&':
result.kind = verIntersect result = VersionRange(kind: verIntersect)
result.verILeft = makeRange(version, op) result.verILeft = makeRange(version, op)
# Parse everything after & # Parse everything after &
@ -204,10 +202,10 @@ proc toVersionRange*(ver: Version): VersionRange =
## Converts a version to either a verEq or verSpecial VersionRange. ## Converts a version to either a verEq or verSpecial VersionRange.
new(result) new(result)
if ver.isSpecial: if ver.isSpecial:
result.kind = verSpecial result = VersionRange(kind: verSpecial)
result.spe = ver result.spe = ver
else: else:
result.kind = verEq result = VersionRange(kind: verEq)
result.ver = ver result.ver = ver
proc parseRequires*(req: string): PkgTuple = proc parseRequires*(req: string): PkgTuple =
@ -263,17 +261,14 @@ proc getSimpleString*(verRange: VersionRange): string =
result = "" result = ""
proc newVRAny*(): VersionRange = proc newVRAny*(): VersionRange =
new(result) result = VersionRange(kind: verAny)
result.kind = verAny
proc newVREarlier*(ver: string): VersionRange = proc newVREarlier*(ver: string): VersionRange =
new(result) result = VersionRange(kind: verEarlier)
result.kind = verEarlier
result.ver = newVersion(ver) result.ver = newVersion(ver)
proc newVREq*(ver: string): VersionRange = proc newVREq*(ver: string): VersionRange =
new(result) result = VersionRange(kind: verEq)
result.kind = verEq
result.ver = newVersion(ver) result.ver = newVersion(ver)
proc findLatest*(verRange: VersionRange, proc findLatest*(verRange: VersionRange,