@@ -6652,13 +6652,20 @@ export class Compiler extends DiagnosticEmitter {
6652
6652
}
6653
6653
6654
6654
/** Checks that an unsafe expression is allowed. */
6655
- private checkUnsafe ( reportNode : Node ) : void {
6655
+ private checkUnsafe ( reportNode : Node , relatedReportNode : Node | null = null ) : void {
6656
6656
// Library files may always use unsafe features
6657
6657
if ( this . options . noUnsafe && ! reportNode . range . source . isLibrary ) {
6658
- this . error (
6659
- DiagnosticCode . Operation_is_unsafe ,
6660
- reportNode . range
6661
- ) ;
6658
+ if ( relatedReportNode ) {
6659
+ this . errorRelated (
6660
+ DiagnosticCode . Operation_is_unsafe ,
6661
+ reportNode . range , relatedReportNode . range
6662
+ ) ;
6663
+ } else {
6664
+ this . error (
6665
+ DiagnosticCode . Operation_is_unsafe ,
6666
+ reportNode . range
6667
+ ) ;
6668
+ }
6662
6669
}
6663
6670
}
6664
6671
@@ -8664,6 +8671,11 @@ export class Compiler extends DiagnosticEmitter {
8664
8671
if ( ctor . hasDecorator ( DecoratorFlags . UNSAFE ) ) this . checkUnsafe ( expression ) ;
8665
8672
}
8666
8673
8674
+ var isManaged = classReference . type . isManaged ;
8675
+ if ( ! isManaged ) {
8676
+ this . checkUnsafe ( expression , findDecorator ( DecoratorKind . UNMANAGED , classReference . decoratorNodes ) ) ;
8677
+ }
8678
+
8667
8679
// check and compile field values
8668
8680
var names = expression . names ;
8669
8681
var numNames = names . length ;
@@ -8672,7 +8684,9 @@ export class Compiler extends DiagnosticEmitter {
8672
8684
var hasErrors = false ;
8673
8685
var exprs = new Array < ExpressionRef > ( numNames + 2 ) ;
8674
8686
var flow = this . currentFlow ;
8675
- var tempLocal = flow . getAutoreleaseLocal ( classReference . type ) ;
8687
+ var tempLocal = isManaged
8688
+ ? flow . getAutoreleaseLocal ( classReference . type )
8689
+ : flow . getTempLocal ( classReference . type ) ;
8676
8690
assert ( numNames == values . length ) ;
8677
8691
for ( let i = 0 , k = numNames ; i < k ; ++ i ) {
8678
8692
let member = members ? members . get ( names [ i ] . text ) : null ;
@@ -8700,14 +8714,15 @@ export class Compiler extends DiagnosticEmitter {
8700
8714
// allocate a new instance first and assign 'this' to the temp. local
8701
8715
exprs [ 0 ] = module . local_set (
8702
8716
tempLocal . index ,
8703
- this . makeRetain (
8704
- this . makeAllocation ( classReference )
8705
- )
8717
+ isManaged
8718
+ ? this . makeRetain ( this . makeAllocation ( classReference ) )
8719
+ : this . makeAllocation ( classReference )
8706
8720
) ;
8707
8721
8708
8722
// once all field values have been set, return 'this'
8709
8723
exprs [ exprs . length - 1 ] = module . local_get ( tempLocal . index , this . options . nativeSizeType ) ;
8710
8724
8725
+ if ( ! isManaged ) flow . freeTempLocal ( tempLocal ) ;
8711
8726
this . currentType = classReference . type ;
8712
8727
return module . flatten ( exprs , this . options . nativeSizeType ) ;
8713
8728
}
0 commit comments