Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

120
Views
Literal entero negativo convertido a tipo entero genérico sin signo sin advertencia

En este simple fragmento de código, estoy usando el literal entero -1 en un contexto donde se espera un valor de tipo T T se ajusta a FixedWidthInteger , por lo que se desconoce en el momento de la compilación si el literal se puede convertir al tipo real T . Si T se establece en un tipo de entero sin signo, el -1 simplemente se convierte en 0 . Hubiera esperado un error de tiempo de ejecución, o al menos una advertencia en tiempo de compilación. ¿Es esto un error o está documentado en alguna parte?

 struct Bad<T: FixedWidthInteger> { func getNegativeOne() -> T { return -1 } } print(Bad<UInt32>().getNegativeOne())

Al ejecutarlo desde la respuesta swift :

 $ swift Welcome to Swift version 5.5.2-dev. Type :help for assistance. 1> [paste code] 0
over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!