@@ -7442,6 +7442,10 @@ export class Compiler extends DiagnosticEmitter {
7442
7442
return module . ref_null ( ) ;
7443
7443
}
7444
7444
this . currentType = options . usizeType ;
7445
+ this . warning (
7446
+ DiagnosticCode . Expression_resolves_to_unusual_type_0 ,
7447
+ expression . range , this . currentType . toString ( )
7448
+ ) ;
7445
7449
return options . isWasm64
7446
7450
? module . i64 ( 0 )
7447
7451
: module . i32 ( 0 ) ;
@@ -7778,38 +7782,10 @@ export class Compiler extends DiagnosticEmitter {
7778
7782
switch ( expression . literalKind ) {
7779
7783
case LiteralKind . ARRAY : {
7780
7784
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
7811
7788
) ;
7812
- return module . unreachable ( ) ;
7813
7789
}
7814
7790
case LiteralKind . FLOAT : {
7815
7791
let floatValue = ( < FloatLiteralExpression > expression ) . value ;
@@ -7875,50 +7851,29 @@ export class Compiler extends DiagnosticEmitter {
7875
7851
}
7876
7852
7877
7853
private compileArrayLiteral (
7878
- elementType : Type ,
7879
- expressions : ( Expression | null ) [ ] ,
7880
- constraints : Constraints ,
7881
- reportNode : Node
7854
+ expression : ArrayLiteralExpression ,
7855
+ constraints : Constraints
7882
7856
) : ExpressionRef {
7883
7857
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
+
7884
7863
var program = this . program ;
7885
- var arrayPrototype = assert ( program . arrayPrototype ) ;
7886
7864
var arrayBufferInstance = assert ( program . arrayBufferInstance ) ;
7887
- var flow = this . currentFlow ;
7888
7865
7889
7866
// block those here so compiling expressions doesn't conflict
7890
7867
var tempThis = flow . getTempLocal ( this . options . usizeType ) ;
7891
7868
var tempDataStart = flow . getTempLocal ( arrayBufferInstance . type ) ;
7892
7869
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 ;
7920
7874
7921
7875
// compile value expressions and find out whether all are constant
7876
+ var length = expressions . length ;
7922
7877
var values = new Array < ExpressionRef > ( length ) ;
7923
7878
var isStatic = true ;
7924
7879
var nativeElementType = elementType . toNativeType ( ) ;
@@ -7966,11 +7921,11 @@ export class Compiler extends DiagnosticEmitter {
7966
7921
program . options . isWasm64
7967
7922
? module . i64 ( elementType . alignLog2 )
7968
7923
: module . i32 ( elementType . alignLog2 ) ,
7969
- module . i32 ( arrayInstance . id ) ,
7924
+ module . i32 ( ( < Class > arrayInstance ) . id ) ,
7970
7925
program . options . isWasm64
7971
7926
? module . i64 ( i64_low ( bufferAddress ) , i64_high ( bufferAddress ) )
7972
7927
: module . i32 ( i64_low ( bufferAddress ) )
7973
- ] , reportNode ) ;
7928
+ ] , expression ) ;
7974
7929
this . currentType = arrayType ;
7975
7930
expr = this . makeRetain ( expr ) ;
7976
7931
if ( arrayType . isManaged ) {
@@ -7985,13 +7940,13 @@ export class Compiler extends DiagnosticEmitter {
7985
7940
}
7986
7941
7987
7942
// 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 ) ;
7989
7944
if ( ! setter ) {
7990
7945
flow . freeTempLocal ( tempThis ) ;
7991
7946
flow . freeTempLocal ( tempDataStart ) ;
7992
7947
this . error (
7993
7948
DiagnosticCode . Index_signature_in_type_0_only_permits_reading ,
7994
- reportNode . range , arrayInstance . internalName
7949
+ expression . range , arrayInstance . internalName
7995
7950
) ;
7996
7951
this . currentType = arrayType ;
7997
7952
return module . unreachable ( ) ;
@@ -8008,11 +7963,11 @@ export class Compiler extends DiagnosticEmitter {
8008
7963
program . options . isWasm64
8009
7964
? module . i64 ( elementType . alignLog2 )
8010
7965
: module . i32 ( elementType . alignLog2 ) ,
8011
- module . i32 ( arrayInstance . id ) ,
7966
+ module . i32 ( ( < Class > arrayInstance ) . id ) ,
8012
7967
program . options . isWasm64
8013
7968
? module . i64 ( 0 )
8014
7969
: module . i32 ( 0 )
8015
- ] , reportNode )
7970
+ ] , expression )
8016
7971
)
8017
7972
)
8018
7973
) ;
0 commit comments