# dmd.initsem

Semantic analysis of initializers.

#### Authors

Walter Bright

#### License

Boost License 1.0

Source: initsem.d

Documentation: https://dlang.org/phobos/dmd_initsem.html

Coverage: https://codecov.io/gh/dlang/dmd/src/master/src/dmd/initsem.d

- `toAssocArrayLiteral`

  #### Declaration

  `Expression `toAssocArrayLiteral`(ArrayInitializer `ai`);`

  If possible, convert array initializer to associative array initializer.

  #### Parameters

  `ArrayInitializer `ai`` | array initializer to be converted

  #### Return Value

  The converted associative array initializer or ErrorExp if ``ai`` is not an associative array initializer.

- `initializerSemantic`

  #### Declaration

  `Initializer `initializerSemantic`(Initializer `init`, Scope* `sc`, ref Type `tx`, NeedInterpret `needInterpret`);`

  Perform semantic analysis on `init`.

  #### Parameters

  `Initializer `init`` | Initializer AST node
  `Scope* `sc`` | context
  `Type `tx`` | type that the initializer needs to become. If `tx` is an incomplete type and the initializer completes it, it is updated to be the complete type. ImportC has incomplete types
  `NeedInterpret `needInterpret`` | if CTFE needs to be run on this, such as if it is the initializer for a const declaration

  #### Return Value

  `Initializer` with completed semantic analysis, `ErrorInitializer` if errors were encountered

- `inferType`

  #### Declaration

  `Initializer `inferType`(Initializer `init`, Scope* `sc`);`

  Translate `init` to an `Expression` in order to infer the type.

  #### Parameters

  `Initializer `init`` | `Initializer` AST node
  `Scope* `sc`` | context

  #### Return Value

  an equivalent `ExpInitializer` if successful, or `ErrorInitializer` if it cannot be translated

- `initializerToExpression`

  #### Declaration

  `Expression `initializerToExpression`(Initializer `init`, Type `itype` = null, const bool `isCfile` = false);`

  Translate `init` to an `Expression`.

  #### Parameters

  `Initializer `init`` | `Initializer` AST node
  `Type `itype`` | if not `null`, type to coerce expression to
  `bool `isCfile`` | default initializers are different with C

  #### Return Value

  `Expression` created, `null` if cannot, `ErrorExp` for other errors