diff --git a/contracts/Test.sol b/contracts/Test.sol index 13dcd44..0f08f89 100644 --- a/contracts/Test.sol +++ b/contracts/Test.sol @@ -276,3 +276,16 @@ library UdvtConflict { return mySecondType.unwrap(t); } } + +library UdvtNoConflict { + type myFirstType is bytes32; + type mySecondType is uint256; + + function unwrap(myFirstType t) internal pure returns (bytes32) { + return myFirstType.unwrap(t); + } + + function unwrap(mySecondType t) internal pure returns (uint256) { + return mySecondType.unwrap(t); + } +} diff --git a/src/core.test.ts.md b/src/core.test.ts.md index d6b89b9..33f56c4 100644 --- a/src/core.test.ts.md +++ b/src/core.test.ts.md @@ -841,6 +841,23 @@ Generated by [AVA](https://avajs.dev). ␊ receive() external payable {}␊ }␊ + ␊ + contract $UdvtNoConflict {␊ + bytes32 public constant __hh_exposed_bytecode_marker = "hardhat-exposed";␊ + ␊ + constructor() payable {␊ + }␊ + ␊ + function $unwrap(UdvtNoConflict.myFirstType t) external pure returns (bytes32 ret0) {␊ + (ret0) = UdvtNoConflict.unwrap(t);␊ + }␊ + ␊ + function $unwrap(UdvtNoConflict.mySecondType t) external pure returns (uint256 ret0) {␊ + (ret0) = UdvtNoConflict.unwrap(t);␊ + }␊ + ␊ + receive() external payable {}␊ + }␊ ` ## snapshot initializers diff --git a/src/core.test.ts.snap b/src/core.test.ts.snap index d19911a..1952adc 100644 Binary files a/src/core.test.ts.snap and b/src/core.test.ts.snap differ diff --git a/src/core.ts b/src/core.ts index 6715548..de29d29 100644 --- a/src/core.ts +++ b/src/core.ts @@ -518,17 +518,13 @@ function getVarUdvtType(varDecl: VariableDeclaration, context: ContractDefinitio } function getUdvtType(typeName: TypeName, context: ContractDefinition, deref: ASTDereferencer, location: StorageLocation | null): string | undefined { - const { typeString, typeIdentifier } = typeName.typeDescriptions; - if (typeof typeString !== 'string' || typeof typeIdentifier !== 'string') { - throw new Error('Missing type information'); - } + try { + if (typeName.nodeType === 'UserDefinedTypeName') { + return deref('UserDefinedValueTypeDefinition', typeName.referencedDeclaration).underlyingType.typeDescriptions.typeString ?? undefined; + } + } catch { /* passthrough */ } - // TODO: recover UDVT underlying properly - if (typeIdentifier.startsWith('t_userDefinedValueType')) { - return 'bytes32'; - } else { - return undefined; - } + return undefined; } function getVariables(contract: ContractDefinition, deref: ASTDereferencer, subset?: Visibility[]): VariableDeclaration[] {