@@ -436,13 +436,15 @@ export class Program extends DiagnosticEmitter {
436
436
// if (classPrototype.isUnmanaged && instancePrototype.isAbstract) {
437
437
// this.error( Unmanaged classes cannot declare abstract methods. );
438
438
// }
439
- classPrototype . instanceMembers . set ( name , prototype ) ;
440
439
if ( declaration . name . kind == NodeKind . CONSTRUCTOR ) {
441
440
if ( classPrototype . constructorPrototype )
442
441
this . error ( DiagnosticCode . Multiple_constructor_implementations_are_not_allowed , declaration . name . range ) ;
443
- else
442
+ else {
443
+ prototype . set ( ElementFlags . CONSTRUCTOR ) ;
444
444
classPrototype . constructorPrototype = prototype ;
445
- }
445
+ }
446
+ } else
447
+ classPrototype . instanceMembers . set ( name , prototype ) ;
446
448
}
447
449
448
450
this . checkOperators ( declaration . decorators , prototype , classPrototype ) ;
@@ -1075,7 +1077,6 @@ export class Program extends DiagnosticEmitter {
1075
1077
case ElementKind . LOCAL :
1076
1078
case ElementKind . FIELD :
1077
1079
if ( ! ( targetType = ( < VariableLikeElement > target ) . type ) . classType ) {
1078
- console . log ( propertyAccess . property . name + " on " + targetType ) ;
1079
1080
this . error ( DiagnosticCode . Property_0_does_not_exist_on_type_1 , propertyAccess . property . range , propertyName , targetType . toString ( ) ) ;
1080
1081
return null ;
1081
1082
}
@@ -1282,10 +1283,10 @@ export enum ElementFlags {
1282
1283
PRIVATE = 1 << 15 ,
1283
1284
/** Is an abstract member. */
1284
1285
ABSTRACT = 1 << 16 ,
1286
+ /** Is a constructor. */
1287
+ CONSTRUCTOR = 1 << 17 ,
1285
1288
/** Is an unmanaged class with limited capabilites. */
1286
- UNMANAGED = 1 << 17 ,
1287
- /** Has already inherited base class static members. */
1288
- HAS_STATIC_BASE_MEMBERS = 1 << 18 ,
1289
+ UNMANAGED = 1 << 18 ,
1289
1290
/** Is scoped. */
1290
1291
SCOPED = 1 << 19 ,
1291
1292
/** Is the start function. */
@@ -1524,17 +1525,6 @@ export class FunctionPrototype extends Element {
1524
1525
this . set ( ElementFlags . INSTANCE ) ;
1525
1526
}
1526
1527
1527
- /** Whether a getter function or not. */
1528
- get isGetter ( ) : bool { return ( this . flags & ElementFlags . GETTER ) != 0 ; }
1529
- set isGetter ( is : bool ) { if ( is ) this . flags |= ElementFlags . GETTER ; else this . flags &= ~ ElementFlags . GETTER ; }
1530
-
1531
- /** Whether a setter function or not. */
1532
- get isSetter ( ) : bool { return ( this . flags & ElementFlags . SETTER ) != 0 ; }
1533
- set isSetter ( is : bool ) { if ( is ) this . flags |= ElementFlags . SETTER ; else this . flags &= ~ ElementFlags . SETTER ; }
1534
-
1535
- // Whether a getter/setter function or not.
1536
- get isAccessor ( ) : bool { return ( this . flags & ( ElementFlags . GETTER | ElementFlags . SETTER ) ) != 0 ; }
1537
-
1538
1528
resolve ( functionTypeArguments : Type [ ] | null = null , contextualTypeArguments : Map < string , Type > | null = null ) : Function | null {
1539
1529
var instanceKey = functionTypeArguments ? typesToString ( functionTypeArguments ) : "" ;
1540
1530
var instance = this . instances . get ( instanceKey ) ;
@@ -1584,29 +1574,11 @@ export class FunctionPrototype extends Element {
1584
1574
var parameterTypes = new Array < Type > ( k ) ;
1585
1575
var typeNode : TypeNode | null ;
1586
1576
for ( i = 0 ; i < k ; ++ i ) {
1587
- if ( typeNode = declaration . parameters [ i ] . type ) {
1588
- var parameterType = this . program . resolveType ( typeNode , contextualTypeArguments , true ) ; // reports
1589
- if ( parameterType ) {
1590
- parameters [ i ] = new Parameter ( declaration . parameters [ i ] . name . name , parameterType , declaration . parameters [ i ] . initializer ) ;
1591
- parameterTypes [ i ] = parameterType ;
1592
- } else
1593
- return null ;
1594
- } else
1595
- return null ;
1596
- }
1597
-
1598
- // resolve return type
1599
- // TODO: 'this' type
1600
- var returnType : Type ;
1601
- if ( this . isSetter ) {
1602
- returnType = Type . void ; // not annotated
1603
- } else {
1604
- if ( typeNode = declaration . returnType ) {
1605
- var type = this . program . resolveType ( < TypeNode > typeNode , contextualTypeArguments , true ) ; // reports
1606
- if ( type )
1607
- returnType = type ;
1608
- else
1609
- return null ;
1577
+ typeNode = assert ( declaration . parameters [ i ] . type ) ;
1578
+ var parameterType = this . program . resolveType ( typeNode , contextualTypeArguments , true ) ; // reports
1579
+ if ( parameterType ) {
1580
+ parameters [ i ] = new Parameter ( declaration . parameters [ i ] . name . name , parameterType , declaration . parameters [ i ] . initializer ) ;
1581
+ parameterTypes [ i ] = parameterType ;
1610
1582
} else
1611
1583
return null ;
1612
1584
}
@@ -1620,6 +1592,21 @@ export class FunctionPrototype extends Element {
1620
1592
if ( ! classInstance )
1621
1593
return null ;
1622
1594
}
1595
+
1596
+ // resolve return type
1597
+ // TODO: 'this' type
1598
+ var returnType : Type ;
1599
+ if ( this . is ( ElementFlags . SETTER ) || this . is ( ElementFlags . CONSTRUCTOR ) ) {
1600
+ returnType = Type . void ; // not annotated
1601
+ } else {
1602
+ typeNode = assert ( declaration . returnType ) ;
1603
+ var type = this . program . resolveType ( < TypeNode > typeNode , contextualTypeArguments , true ) ; // reports
1604
+ if ( type )
1605
+ returnType = type ;
1606
+ else
1607
+ return null ;
1608
+ }
1609
+
1623
1610
instance = new Function ( this , internalName , functionTypeArguments , parameters , returnType , classInstance ) ;
1624
1611
instance . contextualTypeArguments = contextualTypeArguments ;
1625
1612
this . instances . set ( instanceKey , instance ) ;
@@ -1965,8 +1952,7 @@ export class ClassPrototype extends Element {
1965
1952
this . program . error ( DiagnosticCode . Structs_cannot_extend_classes_and_vice_versa , Range . join ( declaration . name . range , declaration . extendsType . range ) ) ;
1966
1953
return null ;
1967
1954
}
1968
- } else
1969
- this . flags |= ElementFlags . HAS_STATIC_BASE_MEMBERS ; // fwiw
1955
+ }
1970
1956
1971
1957
// override call specific contextual type arguments if provided
1972
1958
var i : i32 , k : i32 ;
@@ -1996,6 +1982,13 @@ export class ClassPrototype extends Element {
1996
1982
}
1997
1983
}
1998
1984
1985
+ if ( this . constructorPrototype ) {
1986
+ var partialConstructor = this . constructorPrototype . resolvePartial ( typeArguments ) ; // reports
1987
+ if ( partialConstructor )
1988
+ instance . constructorInstance = partialConstructor . resolve ( ) ; // reports
1989
+ // TODO: ^ doesn't know the return type, hence returns null
1990
+ }
1991
+
1999
1992
if ( this . instanceMembers )
2000
1993
for ( var member of this . instanceMembers . values ( ) ) {
2001
1994
switch ( member . kind ) {
@@ -2086,6 +2079,8 @@ export class Class extends Element {
2086
2079
contextualTypeArguments : Map < string , Type > | null = null ;
2087
2080
/** Current member memory offset. */
2088
2081
currentMemoryOffset : u32 = 0 ;
2082
+ /** Constructor instance. */
2083
+ constructorInstance : Function | null = null ;
2089
2084
2090
2085
/** Constructs a new class. */
2091
2086
constructor ( prototype : ClassPrototype , internalName : string , typeArguments : Type [ ] | null = null , base : Class | null = null ) {
0 commit comments