compiler: fix typeassert without comma-ok for unused types
Этот коммит содержится в:
		
							родитель
							
								
									d948abdf82
								
							
						
					
					
						коммит
						57661a3c76
					
				
					 1 изменённых файлов: 12 добавлений и 1 удалений
				
			
		
							
								
								
									
										13
									
								
								compiler.go
									
										
									
									
									
								
							
							
						
						
									
										13
									
								
								compiler.go
									
										
									
									
									
								
							|  | @ -2334,7 +2334,18 @@ func (c *Compiler) parseExpr(frame *Frame, expr ssa.Value) (llvm.Value, error) { | ||||||
| 			assertedTypeNum, typeExists := c.ir.TypeNum(expr.AssertedType) | 			assertedTypeNum, typeExists := c.ir.TypeNum(expr.AssertedType) | ||||||
| 			if !typeExists { | 			if !typeExists { | ||||||
| 				// Static analysis has determined this type assert will never apply. | 				// Static analysis has determined this type assert will never apply. | ||||||
| 				return llvm.ConstStruct([]llvm.Value{valueNil, llvm.ConstInt(llvm.Int1Type(), 0, false)}, false), nil | 				// Using undef here so that LLVM knows we'll never get here and | ||||||
|  | 				// can optimize accordingly. | ||||||
|  | 				undef := llvm.Undef(assertedType) | ||||||
|  | 				commaOk := llvm.ConstInt(llvm.Int1Type(), 0, false) | ||||||
|  | 				if expr.CommaOk { | ||||||
|  | 					return llvm.ConstStruct([]llvm.Value{undef, commaOk}, false), nil | ||||||
|  | 				} else { | ||||||
|  | 					fn := c.mod.NamedFunction("runtime.interfaceTypeAssert") | ||||||
|  | 					c.builder.CreateCall(fn, []llvm.Value{commaOk}, "") | ||||||
|  | 					c.builder.CreateUnreachable() | ||||||
|  | 					return undef, nil | ||||||
|  | 				} | ||||||
| 			} | 			} | ||||||
| 			if assertedTypeNum >= 1<<16 { | 			if assertedTypeNum >= 1<<16 { | ||||||
| 				return llvm.Value{}, errors.New("interface typecodes do not fit in a 16-bit integer") | 				return llvm.Value{}, errors.New("interface typecodes do not fit in a 16-bit integer") | ||||||
|  |  | ||||||
		Загрузка…
	
	Создание таблицы
		
		Сослаться в новой задаче
	
	 Ayke van Laethem
						Ayke van Laethem