changed type() to typeof() in docs and error messages (#14084)

This commit is contained in:
hlaaftana 2020-04-24 10:22:12 +03:00 • committed by GitHub
commit b2141fc2a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 13 additions and 13 deletions

View file

@ -633,7 +633,7 @@ proc explicitGenericInstantiation(c: PContext, n: PNode, s: PSym): PNode =
if s.ast[genericParamsPos].safeLen != n.len-1: if s.ast[genericParamsPos].safeLen != n.len-1:
let expected = s.ast[genericParamsPos].safeLen let expected = s.ast[genericParamsPos].safeLen
localError(c.config, getCallLineInfo(n), errGenerated, "cannot instantiate: '" & renderTree(n) & localError(c.config, getCallLineInfo(n), errGenerated, "cannot instantiate: '" & renderTree(n) &
"'; got " & $(n.len-1) & " type(s) but expected " & $expected) "'; got " & $(n.len-1) & " typeof(s) but expected " & $expected)
return n return n
result = explicitGenericSym(c, n, s) result = explicitGenericSym(c, n, s)
if result == nil: result = explicitGenericInstError(c, n) if result == nil: result = explicitGenericInstError(c, n)

View file

@ -587,7 +587,7 @@ proc typeToString(typ: PType, prefer: TPreferedDesc = preferName): string =
if t.n == nil: if t.n == nil:
result = "unknown" result = "unknown"
else: else:
result = "type(" & renderTree(t.n) & ")" result = "typeof(" & renderTree(t.n) & ")"
of tyArray: of tyArray:
if t[0].kind == tyRange: if t[0].kind == tyRange:
result = "array[" & rangeToStr(t[0].n) & ", " & result = "array[" & rangeToStr(t[0].n) & ", " &

View file

@ -48,7 +48,7 @@ written as:
a.len = b.len a.len = b.len
a.cap = b.cap a.cap = b.cap
if b.data != nil: if b.data != nil:
a.data = cast[type(a.data)](alloc(a.cap * sizeof(T))) a.data = cast[typeof(a.data)](alloc(a.cap * sizeof(T)))
for i in 0..<a.len: for i in 0..<a.len:
a.data[i] = b.data[i] a.data[i] = b.data[i]
@ -76,7 +76,7 @@ written as:
proc createSeq*[T](elems: varargs[T]): myseq[T] = proc createSeq*[T](elems: varargs[T]): myseq[T] =
result.cap = elems.len result.cap = elems.len
result.len = elems.len result.len = elems.len
result.data = cast[type(result.data)](alloc(result.cap * sizeof(T))) result.data = cast[typeof(result.data)](alloc(result.cap * sizeof(T)))
for i in 0..<result.len: result.data[i] = elems[i] for i in 0..<result.len: result.data[i] = elems[i]
proc len*[T](x: myseq[T]): int {.inline.} = x.len proc len*[T](x: myseq[T]): int {.inline.} = x.len

View file

@ -2354,7 +2354,7 @@ The convertible relation can be relaxed by a user-defined type
echo x # => 97 echo x # => 97
The type conversion ``T(a)`` is an L-value if ``a`` is an L-value and The type conversion ``T(a)`` is an L-value if ``a`` is an L-value and
``typeEqualsOrDistinct(T, type(a))`` holds. ``typeEqualsOrDistinct(T, typeof(a))`` holds.
Assignment compatibility Assignment compatibility

View file

@ -619,7 +619,7 @@ type is an instance of it:
type type
Functor[A] = concept f Functor[A] = concept f
type MatchedGenericType = genericHead(f.type) type MatchedGenericType = genericHead(typeof(f))
# `f` will be a value of a type such as `Option[T]` # `f` will be a value of a type such as `Option[T]`
# `MatchedGenericType` will become the `Option` type # `MatchedGenericType` will become the `Option` type
@ -652,7 +652,7 @@ matched to a concrete type:
t1 < t2 is bool t1 < t2 is bool
type TimeSpan = type(t1 - t2) type TimeSpan = typeof(t1 - t2)
TimeSpan * int is TimeSpan TimeSpan * int is TimeSpan
TimeSpan + TimeSpan is TimeSpan TimeSpan + TimeSpan is TimeSpan

View file

@ -651,7 +651,7 @@ Example: Lifting Procs
## # now abs(@[@[1,-2], @[-2,-3]]) == @[@[1,2], @[2,3]] ## # now abs(@[@[1,-2], @[-2,-3]]) == @[@[1,2], @[2,3]]
proc fname[T](x: openarray[T]): auto = proc fname[T](x: openarray[T]): auto =
var temp: T var temp: T
type outType = type(fname(temp)) type outType = typeof(fname(temp))
result = newSeq[outType](x.len) result = newSeq[outType](x.len)
for i in 0..<x.len: for i in 0..<x.len:
result[i] = fname(x[i]) result[i] = fname(x[i])

View file

@ -83,7 +83,7 @@ proc toJsKey*[T: SomeFloat](text: cstring, t: type T): T {.importcpp: "parseFloa
type type
JsKey* = concept a, type T JsKey* = concept a, type T
cstring.toJsKey(T) is type(a) cstring.toJsKey(T) is T
JsObject* = ref object of JsRoot JsObject* = ref object of JsRoot
## Dynamically typed wrapper around a JavaScript object. ## Dynamically typed wrapper around a JavaScript object.

View file

@ -48,7 +48,7 @@ proc genericHead*(t: typedesc): typedesc {.magic: "TypeTrait".}
## .. code-block:: nim ## .. code-block:: nim
## type ## type
## Functor[A] = concept f ## Functor[A] = concept f
## type MatchedGenericType = genericHead(f.type) ## type MatchedGenericType = genericHead(typeof(f))
## # `f` will be a value of a type such as `Option[T]` ## # `f` will be a value of a type such as `Option[T]`
## # `MatchedGenericType` will become the `Option` type ## # `MatchedGenericType` will become the `Option` type

View file

@ -45,9 +45,9 @@ proc `$`*(t: typedesc): string {.magic: "TypeTrait".}
## `typetraits module <typetraits.html>`_. ## `typetraits module <typetraits.html>`_.
## ##
## .. code-block:: Nim ## .. code-block:: Nim
## doAssert $(type(42)) == "int" ## doAssert $(typeof(42)) == "int"
## doAssert $(type("Foo")) == "string" ## doAssert $(typeof("Foo")) == "string"
## static: doAssert $(type(@['A', 'B'])) == "seq[char]" ## static: doAssert $(typeof(@['A', 'B'])) == "seq[char]"
when defined(nimHasIsNamedTuple): when defined(nimHasIsNamedTuple):
proc isNamedTuple(T: typedesc): bool {.magic: "TypeTrait".} proc isNamedTuple(T: typedesc): bool {.magic: "TypeTrait".}