| 732 | 732 | |
|---|
| 733 | 733 | /* Pick up storage classes from context, but skip synchronized |
|---|
| 734 | 734 | */ |
|---|
| 735 | 735 | storage_class |= (sc->stc & ~STCsynchronized); |
|---|
| 736 | 736 | if (storage_class & STCextern && init) |
|---|
| 737 | 737 | error("extern symbols cannot have initializers"); |
|---|
| 738 | 738 | |
|---|
| 739 | 739 | /* If auto type inference, do the inference |
|---|
| 740 | 740 | */ |
|---|
| 741 | 741 | int inferred = 0; |
|---|
| 742 | 742 | if (!type) |
|---|
| 743 | 743 | { inuse++; |
|---|
| 744 | 744 | |
|---|
| 745 | 745 | ArrayInitializer *ai = init->isArrayInitializer(); |
|---|
| 746 | 746 | if (ai) |
|---|
| 747 | 747 | { Expression *e; |
|---|
| 748 | 748 | if (ai->isAssociativeArray()) |
|---|
| 749 | 749 | e = ai->toAssocArrayLiteral(); |
|---|
| 750 | 750 | else |
|---|
| 751 | 751 | e = init->toExpression(); |
|---|
| 752 | 757 | init = new ExpInitializer(e->loc, e); |
|---|
| 753 | 758 | type = init->inferType(sc); |
|---|
| 754 | 759 | if (type->ty == Tsarray) |
|---|
| 755 | 760 | type = type->nextOf()->arrayOf(); |
|---|
| 756 | 761 | } |
|---|
| 757 | 762 | else |
|---|
| 758 | 763 | type = init->inferType(sc); |
|---|
| 759 | 764 | |
|---|
| 760 | 765 | //printf("test2: %s, %s, %s\n", toChars(), type->toChars(), type->deco); |
|---|
| 761 | 766 | // type = type->semantic(loc, sc); |
|---|
| 762 | 767 | |
|---|
| 763 | 768 | inuse--; |
|---|
| 764 | 769 | inferred = 1; |
|---|
| 765 | 770 | |
|---|
| 766 | 771 | if (init->isArrayInitializer() && type->toBasetype()->ty == Tsarray) |
|---|
| 767 | 772 | { // Prefer array literals to give a T[] type rather than a T[dim] |
|---|
| 768 | 773 | type = type->toBasetype()->nextOf()->arrayOf(); |
|---|
| 769 | 774 | } |
|---|
| 770 | 775 | |
|---|
| 771 | 776 | /* This is a kludge to support the existing syntax for RAII |
|---|