modules/ballerina-core/src/main/java/org/ballerinalang/util/semantics/SemanticAnalyzer.java
@Override
    public void visit(StructInitExpr structInitExpr) {
        BType inheritedType = structInitExpr.getInheritedType();
        structInitExpr.setType(inheritedType);
        Expression[] argExprs = structInitExpr.getArgExprs();
        if (argExprs.length == 0) {
            return;
        }

        StructDef structDef = (StructDef) inheritedType;
        for (Expression argExpr : argExprs) {
            MapStructInitKeyValueExpr keyValueExpr = (MapStructInitKeyValueExpr) argExpr;
            Expression keyExpr = keyValueExpr.getKeyExpr();
            if (!(keyExpr instanceof VariableRefExpr)) {
                BLangExceptionHelper.throwSemanticError(keyExpr, SemanticErrors.INVALID_FIELD_NAME_STRUCT_INIT);
            }

            VariableRefExpr varRefExpr = (VariableRefExpr) keyExpr;
            BLangSymbol varDefSymbol = structDef.resolveMembers(varRefExpr.getSymbolName());
            
            if (varDefSymbol == null) {
                BLangExceptionHelper.throwSemanticError(keyExpr, SemanticErrors.UNKNOWN_FIELD_IN_STRUCT,
                        varRefExpr.getVarName(), structDef.getName());
            }
            
            if (!(varDefSymbol instanceof VariableDef)) {
                BLangExceptionHelper.throwSemanticError(varRefExpr, SemanticErrors.INCOMPATIBLE_TYPES_UNKNOWN_FOUND, 
                        varDefSymbol.getSymbolName());
            }
            
            VariableDef varDef = (VariableDef) varDefSymbol;
            varRefExpr.setVariableDef(varDef);
            Expression valueExpr = keyValueExpr.getValueExpr();
            visitSingleValueExpr(valueExpr);

            if (!valueExpr.getType().equals(varDef.getType()) && (varDef.getType() != BTypes.typeAny)) {
                BLangExceptionHelper.throwSemanticError(keyExpr, SemanticErrors.INCOMPATIBLE_TYPES,
                        varDef.getType(), valueExpr.getType());
            }
        }
    }
/**
     * Visit and analyze ballerina Struct initializing expression.
     */
Visit and analyze ballerina Struct initializing expression.
Visit and analyze ballerina Struct initializing expression .
@Override
    public void visit(StructInitExpr structInitExpr) {
        BType inheritedType = structInitExpr.getInheritedType();
        structInitExpr.setType(inheritedType);
        Expression[] argExprs = structInitExpr.getArgExprs();
        if (argExprs.length == 0) {
            return;
        }
        StructDef structDef = (StructDef) inheritedType;
        for (Expression argExpr : argExprs) {
            MapStructInitKeyValueExpr keyValueExpr = (MapStructInitKeyValueExpr) argExpr;
            Expression keyExpr = keyValueExpr.getKeyExpr();
            if (!(keyExpr instanceof VariableRefExpr)) {
                BLangExceptionHelper.throwSemanticError(keyExpr, SemanticErrors.INVALID_FIELD_NAME_STRUCT_INIT);
            }
            VariableRefExpr varRefExpr = (VariableRefExpr) keyExpr;
            BLangSymbol varDefSymbol = structDef.resolveMembers(varRefExpr.getSymbolName());
            if (varDefSymbol == null) {
                BLangExceptionHelper.throwSemanticError(keyExpr, SemanticErrors.UNKNOWN_FIELD_IN_STRUCT,
                        varRefExpr.getVarName(), structDef.getName());
            }
            if (!(varDefSymbol instanceof VariableDef)) {
                BLangExceptionHelper.throwSemanticError(varRefExpr, SemanticErrors.INCOMPATIBLE_TYPES_UNKNOWN_FOUND, 
                        varDefSymbol.getSymbolName());
            }
            VariableDef varDef = (VariableDef) varDefSymbol;
            varRefExpr.setVariableDef(varDef);
            Expression valueExpr = keyValueExpr.getValueExpr();
            visitSingleValueExpr(valueExpr);
            if (!valueExpr.getType().equals(varDef.getType()) && (varDef.getType() != BTypes.typeAny)) {
                BLangExceptionHelper.throwSemanticError(keyExpr, SemanticErrors.INCOMPATIBLE_TYPES,
                        varDef.getType(), valueExpr.getType());
            }
        }
    }
@ Override public void visit ( StructInitExpr structInitExpr ) { BType inheritedType = structInitExpr . getInheritedType ( ) ; structInitExpr . setType ( inheritedType ) ; Expression [ ] argExprs = structInitExpr . getArgExprs ( ) ; if ( argExprs . length == 0 ) { return ; } StructDef structDef = ( StructDef ) inheritedType ; for ( Expression argExpr : argExprs ) { MapStructInitKeyValueExpr keyValueExpr = ( MapStructInitKeyValueExpr ) argExpr ; Expression keyExpr = keyValueExpr . getKeyExpr ( ) ; if ( ! ( keyExpr instanceof VariableRefExpr ) ) { BLangExceptionHelper . throwSemanticError ( keyExpr , SemanticErrors . INVALID_FIELD_NAME_STRUCT_INIT ) ; } VariableRefExpr varRefExpr = ( VariableRefExpr ) keyExpr ; BLangSymbol varDefSymbol = structDef . resolveMembers ( varRefExpr . getSymbolName ( ) ) ; if ( varDefSymbol == null ) { BLangExceptionHelper . throwSemanticError ( keyExpr , SemanticErrors . UNKNOWN_FIELD_IN_STRUCT , varRefExpr . getVarName ( ) , structDef . getName ( ) ) ; } if ( ! ( varDefSymbol instanceof VariableDef ) ) { BLangExceptionHelper . throwSemanticError ( varRefExpr , SemanticErrors . INCOMPATIBLE_TYPES_UNKNOWN_FOUND , varDefSymbol . getSymbolName ( ) ) ; } VariableDef varDef = ( VariableDef ) varDefSymbol ; varRefExpr . setVariableDef ( varDef ) ; Expression valueExpr = keyValueExpr . getValueExpr ( ) ; visitSingleValueExpr ( valueExpr ) ; if ( ! valueExpr . getType ( ) . equals ( varDef . getType ( ) ) && ( varDef . getType ( ) != BTypes . typeAny ) ) { BLangExceptionHelper . throwSemanticError ( keyExpr , SemanticErrors . INCOMPATIBLE_TYPES , varDef . getType ( ) , valueExpr . getType ( ) ) ; } } }
Visit and analyze ballerina Struct initializing expression.
Visit and analyze ballerina Struct initializing expression .