File tree Expand file tree Collapse file tree 2 files changed +19
-9
lines changed
Expand file tree Collapse file tree 2 files changed +19
-9
lines changed Original file line number Diff line number Diff line change @@ -2793,15 +2793,24 @@ export class Compiler extends DiagnosticEmitter {
27932793 }
27942794
27952795 // Otherwise emit a normal return
2796- return ! expr
2797- ? isLastInBody
2798- ? module . nop ( )
2799- : module . return ( )
2800- : isLastInBody
2801- ? expr
2802- : this . currentType == Type . void
2803- ? module . block ( null , [ expr , module . return ( ) ] )
2804- : module . return ( expr ) ;
2796+ if ( expr ) {
2797+ if ( getExpressionId ( expr ) == ExpressionId . Unreachable ) {
2798+ // emit unreachable directly
2799+ return expr ;
2800+ }
2801+ if ( isLastInBody ) {
2802+ return expr ;
2803+ }
2804+ if ( this . currentType == Type . void ) {
2805+ return module . block ( null , [ expr , module . return ( ) ] ) ;
2806+ }
2807+ return module . return ( expr ) ;
2808+ } else {
2809+ if ( isLastInBody ) {
2810+ return module . nop ( ) ;
2811+ }
2812+ return module . return ( ) ;
2813+ }
28052814 }
28062815
28072816 private compileSwitchStatement (
Original file line number Diff line number Diff line change @@ -658,6 +658,7 @@ class InstrumentReturns extends Pass {
658658 var stmts = new Array < ExpressionRef > ( ) ;
659659 if ( value ) {
660660 let returnType = _BinaryenExpressionGetType ( value ) ;
661+ if ( returnType != TypeRef . Unreachable ) return ;
661662 let temp = this . parentPass . getSharedTemp ( this . currentFunction , returnType ) ;
662663 // t = value
663664 stmts . push (
You can’t perform that action at this time.
0 commit comments