Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/IRGen/MetadataRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3592,8 +3592,8 @@ IRGenFunction::emitTypeMetadataRefForLayout(SILType ty,

llvm::Value *IRGenFunction::emitValueGenericRef(CanType type) {
if (auto integer = type->getAs<IntegerType>()) {
return llvm::ConstantInt::get(IGM.SizeTy,
integer->getValue().zextOrTrunc(IGM.SizeTy->getBitWidth()));
auto value = integer->getValue().sextOrTrunc(IGM.SizeTy->getBitWidth());
return llvm::ConstantInt::get(IGM.SizeTy, value);
}

return tryGetLocalTypeData(type, LocalTypeDataKind::forValue());
Expand Down
27 changes: 26 additions & 1 deletion test/Interpreter/value_generics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@

// REQUIRES: executable_test

struct A<let N: Int, let M: Int> {}
struct A<let N: Int, let M: Int> {
func foo() {
print("Lower: \(N), Upper: \(M)")
}
}

extension A where N == 2 {
struct B {}
Expand Down Expand Up @@ -36,3 +40,24 @@ let x: A<-5, -5> = getA()

// CHECK: main.A<-5, -5>
print(_typeName(type(of: x), qualified: true))

// CHECK: Lower: 1, Upper: 8
A<1, 8>().foo()

// CHECK: Lower: 0, Upper: 8
A<0, 8>().foo()

// CHECK: Lower: -1, Upper: 8
A< -1, 8>().foo()

// CHECK: Lower: -2, Upper: 8
A< -2, 8>().foo()

// CHECK: Lower: -3, Upper: 8
A< -3, 8>().foo()

// CHECK: Lower: -4, Upper: 8
A< -4, 8>().foo()

// CHECK: Lower: -5, Upper: 8
A< -5, 8>().foo()