Skip to content

Commit

Permalink
udvt resolution + test for non conflictiong udvt
Browse files Browse the repository at this point in the history
  • Loading branch information
Amxx committed Mar 28, 2024
1 parent a19eb7b commit ddb39f6
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
13 changes: 13 additions & 0 deletions contracts/Test.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
17 changes: 17 additions & 0 deletions src/core.test.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Binary file modified src/core.test.ts.snap
Binary file not shown.
16 changes: 6 additions & 10 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] {
Expand Down

0 comments on commit ddb39f6

Please sign in to comment.