@@ -7442,6 +7442,10 @@ export class Compiler extends DiagnosticEmitter {
74427442 return module . ref_null ( ) ;
74437443 }
74447444 this . currentType = options . usizeType ;
7445+ this . warning (
7446+ DiagnosticCode . Expression_resolves_to_unusual_type_0 ,
7447+ expression . range , this . currentType . toString ( )
7448+ ) ;
74457449 return options . isWasm64
74467450 ? module . i64 ( 0 )
74477451 : module . i32 ( 0 ) ;
@@ -7778,38 +7782,10 @@ export class Compiler extends DiagnosticEmitter {
77787782 switch ( expression . literalKind ) {
77797783 case LiteralKind . ARRAY : {
77807784 assert ( ! implicitlyNegate ) ;
7781- let elementExpressions = ( < ArrayLiteralExpression > expression ) . elementExpressions ;
7782-
7783- // Infer from first element in auto contexts
7784- if ( contextualType == Type . auto ) {
7785- return this . compileArrayLiteral (
7786- Type . auto ,
7787- elementExpressions ,
7788- constraints ,
7789- expression
7790- ) ;
7791- }
7792-
7793- // Use contextual type if an array
7794- if ( contextualType . is ( TypeFlags . REFERENCE ) ) {
7795- let classType = contextualType . classReference ;
7796- if ( classType ) {
7797- if ( classType . prototype == this . program . arrayPrototype ) {
7798- return this . compileArrayLiteral (
7799- assert ( classType . typeArguments ) [ 0 ] ,
7800- elementExpressions ,
7801- constraints ,
7802- expression
7803- ) ;
7804- }
7805- }
7806- }
7807-
7808- this . error (
7809- DiagnosticCode . The_type_argument_for_type_parameter_0_cannot_be_inferred_from_the_usage_Consider_specifying_the_type_arguments_explicitly ,
7810- expression . range , "T"
7785+ return this . compileArrayLiteral (
7786+ < ArrayLiteralExpression > expression ,
7787+ constraints
78117788 ) ;
7812- return module . unreachable ( ) ;
78137789 }
78147790 case LiteralKind . FLOAT : {
78157791 let floatValue = ( < FloatLiteralExpression > expression ) . value ;
@@ -7875,50 +7851,29 @@ export class Compiler extends DiagnosticEmitter {
78757851 }
78767852
78777853 private compileArrayLiteral (
7878- elementType : Type ,
7879- expressions : ( Expression | null ) [ ] ,
7880- constraints : Constraints ,
7881- reportNode : Node
7854+ expression : ArrayLiteralExpression ,
7855+ constraints : Constraints
78827856 ) : ExpressionRef {
78837857 var module = this . module ;
7858+ var flow = this . currentFlow ;
7859+
7860+ var arrayInstance = this . resolver . lookupExpression ( expression , flow , this . currentType ) ;
7861+ if ( ! arrayInstance ) return module . unreachable ( ) ;
7862+
78847863 var program = this . program ;
7885- var arrayPrototype = assert ( program . arrayPrototype ) ;
78867864 var arrayBufferInstance = assert ( program . arrayBufferInstance ) ;
7887- var flow = this . currentFlow ;
78887865
78897866 // block those here so compiling expressions doesn't conflict
78907867 var tempThis = flow . getTempLocal ( this . options . usizeType ) ;
78917868 var tempDataStart = flow . getTempLocal ( arrayBufferInstance . type ) ;
78927869
7893- // infer common element type in auto contexts
7894- var length = expressions . length ;
7895- if ( elementType == Type . auto ) {
7896- for ( let i = 0 ; i < length ; ++ i ) {
7897- let expression = expressions [ i ] ;
7898- if ( expression ) {
7899- let currentType = this . resolver . resolveExpression ( expression , this . currentFlow , elementType ) ;
7900- if ( ! currentType ) return module . unreachable ( ) ;
7901- if ( elementType == Type . auto ) elementType = currentType ;
7902- else if ( currentType != elementType ) {
7903- let commonType = Type . commonDenominator ( elementType , currentType , false ) ;
7904- if ( commonType ) elementType = commonType ;
7905- // otherwise triggers error further down
7906- }
7907- }
7908- }
7909- if ( elementType /* still */ == Type . auto ) {
7910- this . error (
7911- DiagnosticCode . The_type_argument_for_type_parameter_0_cannot_be_inferred_from_the_usage_Consider_specifying_the_type_arguments_explicitly ,
7912- reportNode . range , "T"
7913- ) ;
7914- return module . unreachable ( ) ;
7915- }
7916- }
7917-
7918- var arrayInstance = assert ( this . resolver . resolveClass ( arrayPrototype , [ elementType ] ) ) ;
7919- var arrayType = arrayInstance . type ;
7870+ assert ( arrayInstance . kind == ElementKind . CLASS ) ;
7871+ var arrayType = ( < Class > arrayInstance ) . type ;
7872+ var elementType = assert ( ( < Class > arrayInstance ) . getTypeArgumentsTo ( this . program . arrayPrototype ) ) [ 0 ] ;
7873+ var expressions = expression . elementExpressions ;
79207874
79217875 // compile value expressions and find out whether all are constant
7876+ var length = expressions . length ;
79227877 var values = new Array < ExpressionRef > ( length ) ;
79237878 var isStatic = true ;
79247879 var nativeElementType = elementType . toNativeType ( ) ;
@@ -7966,11 +7921,11 @@ export class Compiler extends DiagnosticEmitter {
79667921 program . options . isWasm64
79677922 ? module . i64 ( elementType . alignLog2 )
79687923 : module . i32 ( elementType . alignLog2 ) ,
7969- module . i32 ( arrayInstance . id ) ,
7924+ module . i32 ( ( < Class > arrayInstance ) . id ) ,
79707925 program . options . isWasm64
79717926 ? module . i64 ( i64_low ( bufferAddress ) , i64_high ( bufferAddress ) )
79727927 : module . i32 ( i64_low ( bufferAddress ) )
7973- ] , reportNode ) ;
7928+ ] , expression ) ;
79747929 this . currentType = arrayType ;
79757930 expr = this . makeRetain ( expr ) ;
79767931 if ( arrayType . isManaged ) {
@@ -7985,13 +7940,13 @@ export class Compiler extends DiagnosticEmitter {
79857940 }
79867941
79877942 // otherwise compile an explicit instantiation with indexed sets
7988- var setter = arrayInstance . lookupOverload ( OperatorKind . INDEXED_SET , true ) ;
7943+ var setter = ( < Class > arrayInstance ) . lookupOverload ( OperatorKind . INDEXED_SET , true ) ;
79897944 if ( ! setter ) {
79907945 flow . freeTempLocal ( tempThis ) ;
79917946 flow . freeTempLocal ( tempDataStart ) ;
79927947 this . error (
79937948 DiagnosticCode . Index_signature_in_type_0_only_permits_reading ,
7994- reportNode . range , arrayInstance . internalName
7949+ expression . range , arrayInstance . internalName
79957950 ) ;
79967951 this . currentType = arrayType ;
79977952 return module . unreachable ( ) ;
@@ -8008,11 +7963,11 @@ export class Compiler extends DiagnosticEmitter {
80087963 program . options . isWasm64
80097964 ? module . i64 ( elementType . alignLog2 )
80107965 : module . i32 ( elementType . alignLog2 ) ,
8011- module . i32 ( arrayInstance . id ) ,
7966+ module . i32 ( ( < Class > arrayInstance ) . id ) ,
80127967 program . options . isWasm64
80137968 ? module . i64 ( 0 )
80147969 : module . i32 ( 0 )
8015- ] , reportNode )
7970+ ] , expression )
80167971 )
80177972 )
80187973 ) ;
0 commit comments