@@ -352,8 +352,10 @@ export class Compiler extends DiagnosticEmitter {
352
352
return false ;
353
353
} else if ( declaration . initializer ) {
354
354
initExpr = this . compileExpression ( declaration . initializer , Type . void , ConversionKind . NONE ) ; // reports and returns unreachable
355
- if ( this . currentType == Type . void )
355
+ if ( this . currentType == Type . void ) {
356
+ this . error ( DiagnosticCode . Type_0_is_not_assignable_to_type_1 , declaration . range , this . currentType . toString ( ) , "<auto>" ) ;
356
357
return false ;
358
+ }
357
359
global . type = this . currentType ;
358
360
} else {
359
361
this . error ( DiagnosticCode . Type_expected , declaration . name . range . atEnd ) ;
@@ -1010,8 +1012,11 @@ export class Compiler extends DiagnosticEmitter {
1010
1012
init = this . compileExpression ( declaration . initializer , type ) ; // reports and returns unreachable
1011
1013
} else if ( declaration . initializer ) { // infer type
1012
1014
init = this . compileExpression ( declaration . initializer , Type . void , ConversionKind . NONE ) ; // reports and returns unreachable
1013
- if ( ( type = this . currentType ) == Type . void )
1015
+ if ( this . currentType == Type . void ) {
1016
+ this . error ( DiagnosticCode . Type_0_is_not_assignable_to_type_1 , declaration . range , this . currentType . toString ( ) , "<auto>" ) ;
1014
1017
continue ;
1018
+ }
1019
+ type = this . currentType ;
1015
1020
} else {
1016
1021
this . error ( DiagnosticCode . Type_expected , declaration . name . range . atEnd ) ;
1017
1022
continue ;
@@ -1168,8 +1173,8 @@ export class Compiler extends DiagnosticEmitter {
1168
1173
1169
1174
// void to any
1170
1175
if ( fromType . kind == TypeKind . VOID ) {
1171
- this . error ( DiagnosticCode . Operation_not_supported , reportNode . range ) ;
1172
- throw new Error ( "unexpected conversion from void" ) ;
1176
+ this . error ( DiagnosticCode . Type_0_is_not_assignable_to_type_1 , reportNode . range , fromType . toString ( ) , toType . toString ( ) ) ;
1177
+ return this . module . createUnreachable ( ) ;
1173
1178
}
1174
1179
1175
1180
// any to void
@@ -2108,6 +2113,7 @@ export class Compiler extends DiagnosticEmitter {
2108
2113
if ( ! resolved )
2109
2114
return this . module . createUnreachable ( ) ;
2110
2115
2116
+ // to compile just the value, we need to know the target's type
2111
2117
var element = resolved . element ;
2112
2118
var elementType : Type ;
2113
2119
switch ( element . kind ) {
@@ -2143,9 +2149,8 @@ export class Compiler extends DiagnosticEmitter {
2143
2149
this . error ( DiagnosticCode . Operation_not_supported , expression . range ) ;
2144
2150
return this . module . createUnreachable ( ) ;
2145
2151
}
2146
- if ( ! elementType )
2147
- return this . module . createUnreachable ( ) ;
2148
2152
2153
+ // now compile the value and do the assignment
2149
2154
this . currentType = elementType ;
2150
2155
return this . compileAssignmentWithValue ( expression , this . compileExpression ( valueExpression , elementType , ConversionKind . IMPLICIT ) , contextualType != Type . void ) ;
2151
2156
}
@@ -2208,25 +2213,29 @@ export class Compiler extends DiagnosticEmitter {
2208
2213
if ( setterPrototype ) {
2209
2214
var setterInstance = setterPrototype . resolve ( ) ; // reports
2210
2215
if ( setterInstance ) {
2211
- if ( ! tee )
2216
+ assert ( setterInstance . parameters . length == 1 ) ;
2217
+ if ( ! tee ) {
2218
+ this . currentType = Type . void ;
2212
2219
return this . makeCall ( setterInstance , [ valueWithCorrectType ] ) ;
2220
+ }
2213
2221
var getterPrototype = ( < Property > element ) . getterPrototype ;
2214
2222
assert ( getterPrototype != null ) ;
2215
2223
var getterInstance = ( < FunctionPrototype > getterPrototype ) . resolve ( ) ; // reports
2216
- if ( getterInstance )
2224
+ if ( getterInstance ) {
2225
+ assert ( getterInstance . parameters . length == 0 ) ;
2226
+ this . currentType = getterInstance . returnType ;
2217
2227
return this . module . createBlock ( null , [
2218
2228
this . makeCall ( setterInstance , [ valueWithCorrectType ] ) ,
2219
2229
this . makeCall ( getterInstance )
2220
2230
] , getterInstance . returnType . toNativeType ( ) ) ;
2231
+ }
2221
2232
}
2222
2233
} else
2223
2234
this . error ( DiagnosticCode . Cannot_assign_to_0_because_it_is_a_constant_or_a_read_only_property , expression . range , ( < Property > element ) . internalName ) ;
2224
2235
return this . module . createUnreachable ( ) ;
2225
-
2226
- default :
2227
- this . error ( DiagnosticCode . Operation_not_supported , expression . range ) ;
2228
- return this . module . createUnreachable ( ) ;
2229
2236
}
2237
+ this . error ( DiagnosticCode . Operation_not_supported , expression . range ) ;
2238
+ return this . module . createUnreachable ( ) ;
2230
2239
}
2231
2240
2232
2241
compileCallExpression ( expression : CallExpression , contextualType : Type ) : ExpressionRef {
@@ -2527,7 +2536,9 @@ export class Compiler extends DiagnosticEmitter {
2527
2536
var getterInstance = ( < FunctionPrototype > getter ) . resolve ( ) ; // reports
2528
2537
if ( ! getterInstance )
2529
2538
return this . module . createUnreachable ( ) ;
2530
- return this . compileCall ( getterInstance , [ ] , propertyAccess ) ;
2539
+ assert ( getterInstance . parameters . length == 0 ) ;
2540
+ this . currentType = getterInstance . returnType ;
2541
+ return this . makeCall ( getterInstance ) ;
2531
2542
}
2532
2543
this . error ( DiagnosticCode . Operation_not_supported , propertyAccess . range ) ;
2533
2544
return this . module . createUnreachable ( ) ;
0 commit comments