     cb null
 
 
+# TODO: should be moved to inspect
+#
+# Finds type name within *typeSpecification* object.
+findTypeName = (typeSpec) ->
+  typeSpec?.name?.name
+
+
+# Provides nested types as array of type names
+# for given *typeSpecification* object.
+simplifyNestedTypes = (typeSpec, cb) ->
+  return cb null, [] if (typeSpec?.nestedTypes?.length or 0) < 1  # no nested types
+  name = findTypeName typeSpec
+
+  # just playing safe, this should be already ensured by MSON parser
+  if name not in ['array', 'enum']
+    return cb new Error "Nested types are allowed only for array and enum types."
+
+  nested = (typeName.name for typeName in typeSpec.nestedTypes)
+  async.map nested, ensureBaseType, (err) ->
+    return cb err if err  # non-base types result in error
+    cb null, nested
+
+
 # Turns *typeSpecification* object as described in
 # https://github.com/apiaryio/mson-ast#type-definition into something simpler:
 #

# However, this 'race condition' probably can't happen anyway, so these
# approaches shouldn't(tm) make a difference.
isObject = (node) ->
  sections = node.sections or []
  memberSections = sections.filter (section) ->
    section.type is 'member'
  memberSections.length > 0


# Resolves implicit type for given *Named Type* or *Property Member*
# or *Value Member* tree node.
resolveImplicitType = (node, cb) ->
  isArr = isArray node
  isObj = isObject node

# base types only, ends with an error (Boutique builds no symbol table,
# so it can't resolve any possible inheritance).
simplifyTypeSpecification = (typeSpec, cb) ->
  name = findTypeName typeSpec
  return cb null, null if not name  # no type name? return null...

  async.waterfall [
    (next) -> ensureBaseType name, next
    (next) -> simplifyNestedTypes typeSpec, next
  ], (err, nested) ->
    cb err, ({name, nested} unless err)


# Helps to identify whether given node is an implicit array.
